├── .Rbuildignore ├── .Rhistory ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── boot_levinsohn_petrin.R ├── boot_olley_pakes.R ├── boot_wooldridge.R ├── estprod_data.R ├── fs.R ├── interactions.R ├── levinsohn_petrin.R ├── olley_pakes.R ├── panel_lag.R ├── poly_elements.R ├── poly_name.R ├── print.estprod.R ├── ss_lp_gross.R ├── ss_lp_va.R ├── ss_op.R ├── summary.estprod.R └── wooldridge.R ├── README.md ├── data └── estprod_data.rda └── man ├── estprod_data.Rd ├── interactions.Rd ├── levinsohn_petrin.Rd ├── olley_pakes.Rd ├── panel_lag.Rd ├── poly_elements.Rd └── wooldridge.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.Rhistory: -------------------------------------------------------------------------------- 1 | #' @param bootstrap An optional logical. If TRUE calculate bootstrap standard errors. 2 | #' @param reps The number of bootstrap replications. 3 | #' @param degree A vector with the number of polynomial interactions in each stage of the routine. 4 | #' @param verify Verify if inputs are sorted. 5 | #' @param maxiter Parameter of \code{nls.lm} at second stage. 6 | #' @param ... Additional arguments. 7 | #' @details Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 8 | #' It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 9 | #' The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 10 | #' @examples 11 | #' data(estprod_data) 12 | #' levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 13 | #' exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 14 | #' @export 15 | levinsohn_petrin <- function(data, formula = y ~ free | capital | proxy | controls, exit = NULL, gross = FALSE, id = "id", time = "year", 16 | bootstrap = TRUE, reps = 2, degree = c(3, 3), verify = TRUE, maxiter = 100, ...){ 17 | formula <- Formula::Formula(formula) 18 | #----------------------------------------------------- 19 | #verify it has minimun arguments 20 | #----------------------------------------------------- 21 | if (max(length(formula)) < 3){ 22 | stop("The right hand side of the formula must constain at least the first three parts!") 23 | } 24 | if (!exists("data")){ 25 | stop("Data is missing!") 26 | } 27 | data_df <- as.data.frame(data) 28 | id <- data_df[, id] 29 | time <- data_df[, time] 30 | if (!identical(order(id, time), 1:length(id))) { 31 | if (verify) { 32 | stop("Panel not sorted.") 33 | } 34 | } 35 | called_func <- match.call() 36 | #----------------------------------------------------- 37 | #Matrizes a partir da formula_fs 38 | #----------------------------------------------------- 39 | n_length <- dim(data)[1] 40 | free <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 1)) 41 | colnames(free) <- labels(terms(formula(formula, lhs = 0, rhs = 1))) 42 | free_names <- colnames(free) 43 | capital <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 2)) 44 | colnames(capital) <- labels(terms(formula(formula, lhs = 0, rhs = 2))) 45 | capital_names <- colnames(capital) 46 | proxy <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 3)) 47 | colnames(proxy) <- labels(terms(formula(formula, lhs = 0, rhs = 3))) 48 | proxy_names <- colnames(proxy) 49 | if (length(formula)[2] == 4){ 50 | controls <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 4)) 51 | colnames(controls) <- labels(terms(formula(formula, lhs = 0, rhs = 4))) 52 | controls_names <- colnames(controls) 53 | controls_length <- dim(controls)[2] 54 | } else { 55 | #será zero para primeiro estagio funcionar 56 | controls <- as.matrix(rep(0, n_length)) 57 | controls_length <- 0 58 | controls_names <- "zero" 59 | colnames(controls) <- controls_names 60 | } 61 | y <- as.matrix(model.frame(formula, data = data, lhs = 1, rhs = 0)) 62 | k_length <- dim(capital)[2] 63 | free_length <- dim(free)[2] 64 | proxy_length <- dim(proxy)[2] 65 | ############################################ 66 | #Primeiro Estágio 67 | ############################################ 68 | #prev <- sapply(ls(), function(x) get(x), simplify = F, USE.NAMES = T) 69 | first_stage <- fs(data = data_df, y = y, free = free, capital = capital, proxy = proxy, controls = controls, exit = exit, id = id, time = time, formula = formula, degree = degree) 70 | ############################################ 71 | #Segundo Estágio 72 | ############################################ 73 | if (gross == TRUE) { 74 | second_stage <- ss_lp_gross(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, 75 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free 76 | maxiter = maxiter) 77 | } else { 78 | second_stage <- ss_lp_va(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, degree = degree, 79 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, 80 | maxiter = maxiter) 81 | utils::globalVariables(c("phi", "myprobit_lag", "beta_fs_matrix", "beta_fs_free", "beta_fs_controls", "ss_reg")) 82 | #' @title Levinsohn-Petrin Estimation of Production Functions 83 | #' @description This function aims the estimation of production functions using \href{http://www.nber.org/papers/w7819}{Levinsohn-Petrin (2000)}. 84 | #' @param data A data.frame or tibble containing the variables of the model. 85 | #' @param formula An object of the class \code{\link[stats]{formula}}. 86 | #' @param exit An optional formula with the name of the variabe indicator of firm's last period. \emph{~exit}, for example. 87 | #' @param gross If TRUE dependent variable is gross output. 88 | #' @param id A character with the name of the indicator variable. 89 | #' @param time A character with the name of the time variable. 90 | #' @param bootstrap An optional logical. If TRUE calculate bootstrap standard errors. 91 | #' @param reps The number of bootstrap replications. 92 | #' @param degree A vector with the number of polynomial interactions in each stage of the routine. 93 | #' @param verify Verify if inputs are sorted. 94 | #' @param maxiter Parameter of \code{nls.lm} at second stage. 95 | #' @param ... Additional arguments. 96 | #' @details Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 97 | #' It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 98 | #' The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 99 | #' @examples 100 | #' data(estprod_data) 101 | #' levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 102 | #' exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 103 | #' @export 104 | levinsohn_petrin <- function(data, formula = y ~ free | capital | proxy | controls, exit = NULL, gross = FALSE, id = "id", time = "year", 105 | bootstrap = TRUE, reps = 2, degree = c(3, 3), verify = TRUE, maxiter = 100, ...){ 106 | formula <- Formula::Formula(formula) 107 | #----------------------------------------------------- 108 | #verify it has minimun arguments 109 | #----------------------------------------------------- 110 | if (max(length(formula)) < 3){ 111 | stop("The right hand side of the formula must constain at least the first three parts!") 112 | } 113 | if (!exists("data")){ 114 | stop("Data is missing!") 115 | } 116 | data_df <- as.data.frame(data) 117 | id <- data_df[, id] 118 | time <- data_df[, time] 119 | if (!identical(order(id, time), 1:length(id))) { 120 | if (verify) { 121 | stop("Panel not sorted.") 122 | } 123 | } 124 | called_func <- match.call() 125 | #----------------------------------------------------- 126 | #Matrizes a partir da formula_fs 127 | #----------------------------------------------------- 128 | n_length <- dim(data)[1] 129 | free <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 1)) 130 | colnames(free) <- labels(terms(formula(formula, lhs = 0, rhs = 1))) 131 | free_names <- colnames(free) 132 | capital <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 2)) 133 | colnames(capital) <- labels(terms(formula(formula, lhs = 0, rhs = 2))) 134 | capital_names <- colnames(capital) 135 | proxy <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 3)) 136 | colnames(proxy) <- labels(terms(formula(formula, lhs = 0, rhs = 3))) 137 | proxy_names <- colnames(proxy) 138 | if (length(formula)[2] == 4){ 139 | controls <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 4)) 140 | colnames(controls) <- labels(terms(formula(formula, lhs = 0, rhs = 4))) 141 | controls_names <- colnames(controls) 142 | controls_length <- dim(controls)[2] 143 | } else { 144 | #será zero para primeiro estagio funcionar 145 | controls <- as.matrix(rep(0, n_length)) 146 | controls_length <- 0 147 | controls_names <- "zero" 148 | colnames(controls) <- controls_names 149 | } 150 | y <- as.matrix(model.frame(formula, data = data, lhs = 1, rhs = 0)) 151 | k_length <- dim(capital)[2] 152 | free_length <- dim(free)[2] 153 | proxy_length <- dim(proxy)[2] 154 | ############################################ 155 | #Primeiro Estágio 156 | ############################################ 157 | #prev <- sapply(ls(), function(x) get(x), simplify = F, USE.NAMES = T) 158 | first_stage <- fs(data = data_df, y = y, free = free, capital = capital, proxy = proxy, controls = controls, exit = exit, id = id, time = time, formula = formula, degree = degree) 159 | ############################################ 160 | #Segundo Estágio 161 | ############################################ 162 | if (gross == TRUE) { 163 | second_stage <- ss_lp_gross(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, 164 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, 165 | maxiter = maxiter) 166 | } else { 167 | second_stage <- ss_lp_va(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, degree = degree, 168 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, 169 | maxiter = maxiter) 170 | } 171 | ############################################# 172 | #bootstrap 173 | ############################################# 174 | if (bootstrap == TRUE){ 175 | call_boot <- lazyeval::call_modify(called_func, new_args = list(data = quote(data_df), statistic = quote(boot_levinsohn_petrin), R = reps, strata = quote(id), bootstrap = FALSE)) 176 | call_boot[[1]] <- quote(boot::boot) 177 | boot_result <- eval(call_boot) 178 | boot_result[["Call"]] <- called_func 179 | boot_result[["varnames"]] <- c(free_names, 180 | capital_names, 181 | switch((gross > 0) + 1 , NULL, proxy_names), 182 | switch((controls_length > 0) + 1 , NULL, controls_names)) 183 | class(boot_result) <- c("estprod", "boot") 184 | return(boot_result) 185 | } 186 | ############################################# 187 | #No bootstrap 188 | ############################################# 189 | results <- list() 190 | results[["Call"]] <- called_func 191 | #display proxy coefficients if gross = F subtract one 192 | Coefficients <- matrix(c(beta_fs_free, 193 | ss_reg$par[1:k_length], 194 | switch((gross > 0) + 1 , NULL, ss_reg$par[(k_length + 1):(k_length + proxy_length)]), 195 | switch((controls_length > 0) + 1 , NULL, ss_reg$par[(k_length + proxy_length*gross + 1 ):(k_length + proxy_length*gross + controls_length)])), 196 | ncol = 1) 197 | rownames(Coefficients) <- c(free_names, 198 | capital_names, 199 | switch((gross > 0) + 1 , NULL, proxy_names), 200 | switch((controls_length > 0) + 1 , NULL, controls_names)) 201 | colnames(Coefficients) <- c("Estimate") 202 | results[["Coefficients"]] <- Coefficients 203 | attr(results, "class") <- c("estprod", "list") 204 | return(results) 205 | } 206 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 207 | exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 208 | boot_levinsohn_petrin <- function(data, index, ...){ 209 | data <- data[index, ] 210 | results <- levinsohn_petrin(data = data, verify = FALSE, ...) 211 | c(results[["Coefficients"]]) 212 | } 213 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 214 | exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 215 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 216 | exit = ~exit, id = "id", time = "year", bootstrap = F) 217 | ss_lp_va <- function(y, free, capital, proxy, controls, id, time, phi, myprobit_lag, degree, k_length, proxy_length, controls_length, beta_fs_matrix, beta_fs_free, maxiter, ...) { 218 | #----------------------------------------------------- 219 | #Segundo estágio (ss) valor adicionad 220 | #----------------------------------------------------- 221 | capital_lag = panel_lag(capital, id, time, verify = FALSE) 222 | colnames(capital_lag) <- paste0("lag_", colnames(capital_lag)) 223 | names_capital_lag <- colnames(capital_lag) 224 | controls_lag = panel_lag(controls, id, time, verify = FALSE) 225 | colnames(controls_lag) <- paste0("lag_", colnames(controls)) 226 | names_controls_lag <- colnames(controls_lag) 227 | df_ss <- cbind(y_ss = c(y), 228 | free, 229 | capital, 230 | capital_lag, 231 | phi = c(phi), 232 | phi_lag = c(panel_lag(phi, id, time, verify = FALSE)), 233 | controls, 234 | controls_lag) 235 | df_ss <- df_ss[complete.cases(df_ss),] 236 | #rm(phi, capital_lag, controls_lag) 237 | #objective function = sum of residuals ^2 238 | objective <- function(start, data_ss = df_ss) { 239 | #constante: primeira variável. beta_k: (1 + 1) até o numero de k + 1 240 | #beta_poly: as demais 241 | beta_k <- start[1:k_length] 242 | beta_ss_controls <- start[-1:-k_length] 243 | data_ss <- as.matrix(data_ss) 244 | #omega = phi - beta_k * k 245 | data_ss <- cbind(data_ss, 246 | omega = c(data_ss[, "phi"] - as.matrix(data_ss[, colnames(capital)]) %*% as.matrix(beta_k) - data_ss[, colnames(controls)] %*% as.matrix(beta_ss_controls)), 247 | lag_omega = c(data_ss[, "phi_lag"] - data_ss[, names_capital_lag] %*% as.matrix(beta_k) - data_ss[, names_controls_lag] %*% as.matrix(beta_ss_controls))) 248 | omega_pol <- cbind(const = 1, poly(cbind(data_ss[, "lag_omega"], myprobit_lag), degree = degree[2])) 249 | omega_pol <- qr(omega_pol) 250 | omega_hat <- qr.fitted(omega_pol, data_ss[, "omega"]) 251 | data_ss <- as.matrix(data_ss) 252 | lp <- data_ss[, colnames(free)] %*% as.matrix(beta_fs_free) + data_ss[, colnames(capital)] %*% as.matrix(beta_k) + data_ss[, colnames(controls)] %*% as.matrix(beta_ss_controls) + as.matrix(omega_hat) 253 | lp <- (data_ss[, 1] - lp) 254 | return(lp) 255 | } 256 | #n_start = n_capital 257 | start <- rep(0, (k_length + switch((controls_length > 0) + 1 , 1, controls_length))) 258 | ss_reg <- minpack.lm::nls.lm(par = start, fn = objective, control = minpack.lm:::nls.lm.control(maxiter = maxiter)) 259 | assign("ss_reg", ss_reg, envir = parent.frame()) 260 | } 261 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 262 | exit = ~exit, id = "id", time = "year", bootstrap = F) 263 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 264 | exit = ~exit, id = "id", time = "year", bootstrap = T) 265 | library(roxygen2) 266 | library(devtools) 267 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 268 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 269 | devtools::document() 270 | devtools::build() 271 | library(roxygen2) 272 | library(devtools) 273 | setwd("D:/Google Drive 2/R/Functions/Package/") 274 | install("estprod") 275 | library(estprod) 276 | ?olley_pakes 277 | data(estprod_data) 278 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 279 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 280 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 281 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 282 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 283 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 284 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 285 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 286 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 287 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 288 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 289 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 290 | #Sem exit 291 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 292 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 293 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 294 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 295 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 296 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 297 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F, gross = TRUE) 298 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T, gross = TRUE) 299 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 300 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 301 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F, gross = TRUE) 302 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T, gross = TRUE) 303 | library(roxygen2) 304 | library(devtools) 305 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 306 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 307 | devtools::document() 308 | devtools::build() 309 | library(roxygen2) 310 | library(devtools) 311 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 312 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 313 | devtools::document() 314 | devtools::build() 315 | library(roxygen2) 316 | library(devtools) 317 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 318 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 319 | devtools::document() 320 | devtools::build() 321 | library(roxygen2) 322 | library(devtools) 323 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 324 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 325 | devtools::document() 326 | devtools::build() 327 | check_built("D:/Google Drive 2/R/Functions/Package/estprod_0.0.1.tar.gz") 328 | ??`:::` 329 | library(roxygen2) 330 | library(devtools) 331 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 332 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 333 | devtools::document() 334 | devtools::build() 335 | library(roxygen2) 336 | library(devtools) 337 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 338 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 339 | devtools::document() 340 | devtools::build() 341 | library(roxygen2) 342 | library(devtools) 343 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 344 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 345 | devtools::document() 346 | devtools::build() 347 | library(roxygen2) 348 | library(devtools) 349 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 350 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 351 | devtools::document() 352 | devtools::build() 353 | check_built("D:/Google Drive 2/R/Functions/Package/estprod_0.0.1.tar.gz") 354 | library(roxygen2) 355 | library(devtools) 356 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 357 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 358 | devtools::document() 359 | devtools::build() 360 | library(roxygen2) 361 | library(devtools) 362 | setwd("D:/Google Drive 2/R/Functions/Package/") 363 | install("estprod") 364 | library(estprod) 365 | ?olley_pakes 366 | data(estprod_data) 367 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 368 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 369 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 370 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 371 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 372 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 373 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 374 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 375 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 376 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 377 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 378 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 379 | #Sem exit 380 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 381 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 382 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 383 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 384 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 385 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 386 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F, gross = TRUE) 387 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T, gross = TRUE) 388 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 389 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 390 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F, gross = TRUE) 391 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T, gross = TRUE) 392 | library(roxygen2) 393 | library(devtools) 394 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 395 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 396 | devtools::document() 397 | devtools::build() 398 | library(roxygen2) 399 | library(devtools) 400 | setwd("D:/Google Drive 2/R/Functions/Package/") 401 | install("estprod") 402 | library(estprod) 403 | ?olley_pakes 404 | data(estprod_data) 405 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 406 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 407 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 408 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 409 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 410 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 411 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 412 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 413 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 414 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 415 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 416 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 417 | #Sem exit 418 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 419 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 420 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 421 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 422 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 423 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 424 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F, gross = TRUE) 425 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T, gross = TRUE) 426 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 427 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 428 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F, gross = TRUE) 429 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T, gross = TRUE) 430 | library(roxygen2) 431 | library(devtools) 432 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 433 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 434 | devtools::document() 435 | devtools::build() 436 | library(roxygen2) 437 | library(devtools) 438 | setwd("D:/Google Drive 2/R/Functions/Package/") 439 | install("estprod") 440 | library(estprod) 441 | ?olley_pakes 442 | data(estprod_data) 443 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 444 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 445 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 446 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 447 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 448 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 449 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 450 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 451 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 452 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 453 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 454 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 455 | #Sem exit 456 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 457 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 458 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 459 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 460 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 461 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 462 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F, gross = TRUE) 463 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T, gross = TRUE) 464 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 465 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 466 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F, gross = TRUE) 467 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T, gross = TRUE) 468 | library(roxygen2) 469 | library(devtools) 470 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 471 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 472 | devtools::document() 473 | devtools::build() 474 | library(roxygen2) 475 | library(devtools) 476 | setwd("D:/Google Drive 2/R/Functions/Package/") 477 | install("estprod") 478 | library(estprod) 479 | ?olley_pakes 480 | data(estprod_data) 481 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 482 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 483 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 484 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 485 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F) 486 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T) 487 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 488 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 489 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F) 490 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T) 491 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = F, gross = TRUE) 492 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, exit = ~exit, id = "id", time = "year", bootstrap = T, gross = TRUE) 493 | #Sem exit 494 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 495 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 496 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 497 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 498 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F) 499 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T) 500 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = F, gross = TRUE) 501 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, id = "id", time = "year", bootstrap = T, gross = TRUE) 502 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F) 503 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T) 504 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = F, gross = TRUE) 505 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4 | var5, id = "id", time = "year", bootstrap = T, gross = TRUE) 506 | library(roxygen2) 507 | library(devtools) 508 | setwd("D:/Google Drive 2/R/Functions/Package/estprod/") 509 | use_data(estprod_data, pkg = "./data", compress = "bzip2", internal = FALSE, overwrite = F) 510 | devtools::document() 511 | devtools::build() 512 | check_built("D:/Google Drive 2/R/Functions/Package/estprod_0.0.1.tar.gz") 513 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | cache: packages 3 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: estprod 2 | Title: Estimation of Production Functions 3 | Version: 1.1 4 | Date: 2018-05-01 5 | Authors@R: c(person("Rodrigo", "R Remédio", , email = "rremedio@hotmail.com", role = c("aut", "cre"))) 6 | Description: Estimation of production functions by the Olley-Pakes, Levinsohn-Petrin and Wooldridge methodologies. 7 | The package aims to reproduce the results obtained with the Stata's user written opreg and levpet commands. 8 | The first was originally proposed by Olley, G.S. and Pakes, A. (1996) . 9 | The second by Levinsohn, J. and Petrin, A. (2003) . 10 | And the third by Wooldridge (2009) . 11 | Depends: R (>= 3.0) 12 | License: GPL-3 13 | Encoding: UTF-8 14 | LazyData: true 15 | RoxygenNote: 6.0.1 16 | Imports: lazyeval, boot, minpack.lm, Formula, gmm 17 | NeedsCompilation: no 18 | Packaged: 2018-05-01 18:21:48 UTC; Rodrigo 19 | Author: Rodrigo R Remédio [aut, cre] 20 | Maintainer: Rodrigo R Remédio 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,estprod) 4 | S3method(summary,estprod) 5 | export(interactions) 6 | export(levinsohn_petrin) 7 | export(olley_pakes) 8 | export(wooldridge) 9 | export(panel_lag) 10 | export(poly_elements) 11 | importFrom("stats", "binomial", "complete.cases", "glm", "model.frame", 12 | "pnorm", "poly", "predict", "printCoefmat", "terms", "var", 13 | "as.formula") 14 | importFrom("utils", "read.table") -------------------------------------------------------------------------------- /R/boot_levinsohn_petrin.R: -------------------------------------------------------------------------------- 1 | boot_levinsohn_petrin <- function(data, index, ...){ 2 | data <- data[index, ] 3 | results <- levinsohn_petrin(data = data, verify = FALSE, ...) 4 | c(results[["Coefficients"]]) 5 | } 6 | -------------------------------------------------------------------------------- /R/boot_olley_pakes.R: -------------------------------------------------------------------------------- 1 | boot_olley_pakes <- function(data, index, ...){ 2 | data <- data[index, ] 3 | results <- olley_pakes(data = data, verify = FALSE, ...) 4 | c(results[["Coefficients"]]) 5 | } -------------------------------------------------------------------------------- /R/boot_wooldridge.R: -------------------------------------------------------------------------------- 1 | boot_wooldridge <- function(data, index, ...){ 2 | data <- data[index, ] 3 | results <- wooldridge(data = data, verify = FALSE, ...) 4 | c(results[["Coefficients"]][, 1]) 5 | } 6 | -------------------------------------------------------------------------------- /R/estprod_data.R: -------------------------------------------------------------------------------- 1 | #' 10000 randomly generated variables in panel data format. 2 | #' 3 | #' 4 | #' @format A data frame with 10000 rows and 10 variables: 5 | #' \describe{ 6 | #' \item{id}{Identifies the 1000 randomly generated individuals.} 7 | #' \item{year}{The year associated to each individual observation.} 8 | #' \item{g1}{Put individuals in 25 groups.} 9 | #' \item{g2}{Put individuals in 50 groups.} 10 | #' \item{var1}{Randomly generated variable.} 11 | #' \item{var2}{Randomly generated variable.} 12 | #' \item{var3}{Randomly generated variable.} 13 | #' \item{var4}{Randomly generated variable.} 14 | #' \item{var5}{Randomly generated variable.} 15 | #' \item{exit}{The last year an id appears.} 16 | #'} 17 | "estprod_data" -------------------------------------------------------------------------------- /R/fs.R: -------------------------------------------------------------------------------- 1 | if(getRversion() >= "2.15.1") utils::globalVariables(c("phi")) 2 | fs <- function(data, y, free, capital, proxy, controls, formula, exit, degree, id, time){ 3 | 4 | # for (i in 1:length(prev_stage)){ 5 | # assign(names(prev_stage[i]), prev_stage[[i]]) 6 | # } 7 | 8 | #----------------------------------------------------- 9 | #Primeiro estagio (fs): b=(X1'X1)^(-1)X1'Y 10 | #----------------------------------------------------- 11 | polyvars <- cbind(poly(cbind(capital, proxy), degree = degree[1], raw = TRUE)) 12 | 13 | x_fs_qr <- qr(cbind(const = 1, free, polyvars, controls)) 14 | 15 | beta_fs_matrix <- qr.coef(x_fs_qr, y) 16 | 17 | #beta_fs_free <- beta_fs_matrix[2:(2 + free_length - 1)] 18 | beta_fs_free <- beta_fs_matrix[colnames(free),] 19 | 20 | if (length(formula)[2] == 4){ 21 | beta_fs_controls <- beta_fs_matrix[colnames(controls),] 22 | names(beta_fs_controls) <- colnames(controls) 23 | } else { 24 | beta_fs_controls <- 0 25 | } 26 | 27 | 28 | predict_fs_matrix <- qr.fitted(x_fs_qr, y) 29 | 30 | residuals_fs_matrix <- qr.resid(x_fs_qr, y) 31 | 32 | 33 | phi <- predict_fs_matrix - free %*% beta_fs_free - beta_fs_matrix[[1]] - controls %*% beta_fs_controls 34 | 35 | #----------------------------------------------------- 36 | #Probit 37 | #----------------------------------------------------- 38 | #se a variável exit_fs foi definida, gere valores de probit 39 | if (!is.null(exit)){ 40 | exit_formula <- formula(exit) 41 | exit <- as.matrix(model.frame(exit_formula, data = data)) 42 | colnames(exit) <- labels(terms(formula(exit_formula))) 43 | 44 | if (dim(exit)[2] > 1){ 45 | stop("There must be only one exit variable.") 46 | } 47 | } 48 | 49 | 50 | 51 | if (!is.null(exit)){ 52 | if (min(exit, na.rm = TRUE) < 0 | max(exit, na.rm = TRUE) > 1){ 53 | stop("exit values must be 0 <= exit <= 1") 54 | } else if (min(exit, na.rm = TRUE) >= 0 & max(exit, na.rm = TRUE) <= 1){ 55 | 56 | probit_df <- cbind(polyvars, controls) 57 | 58 | probit_df <- panel_lag(probit_df, id = id, time = time, lag = 1, verify = F) 59 | 60 | probit_df <- cbind(probit_df, exit) 61 | 62 | probit_df <- as.data.frame(probit_df[complete.cases(probit_df),]) 63 | 64 | myprobit_lag <- suppressWarnings(glm(exit ~ . + 1, family = binomial(link = "probit"), data = probit_df, maxit = 100)) 65 | 66 | myprobit_lag <- suppressWarnings(predict(myprobit_lag, type = "response")) 67 | 68 | } 69 | 70 | } else { 71 | 72 | myprobit_lag <- NULL 73 | 74 | } 75 | 76 | assign("phi", phi, envir = parent.frame()) 77 | assign("beta_fs_free", beta_fs_free, envir = parent.frame()) 78 | assign("beta_fs_controls", beta_fs_controls, envir = parent.frame()) 79 | assign("beta_fs_matrix", beta_fs_matrix, envir = parent.frame()) 80 | assign("myprobit_lag", myprobit_lag, envir = parent.frame()) 81 | assign("residuals_fs_matrix", residuals_fs_matrix, envir = parent.frame()) 82 | 83 | } 84 | -------------------------------------------------------------------------------- /R/interactions.R: -------------------------------------------------------------------------------- 1 | #' @title Total number of \code{poly} elements. 2 | #' @description This function aims calculates the total number of terms of a polynomial interactions. 3 | #' @param n The number of variables. 4 | #' @param d Degreess of the polynomial interaction. 5 | #' @export 6 | interactions <- function (n, d) { 7 | k <- choose(n, d) 8 | if (d > 1) k <- k + n * sum(choose(n-1, 0:(d-2))) 9 | return(k) 10 | } -------------------------------------------------------------------------------- /R/levinsohn_petrin.R: -------------------------------------------------------------------------------- 1 | utils::globalVariables(c("phi", "myprobit_lag", "beta_fs_matrix", "beta_fs_free", "beta_fs_controls", "ss_reg", "nls.lm.control")) 2 | #' @title Levinsohn-Petrin Estimation of Production Functions 3 | #' @description This function aims the estimation of production functions using \href{http://www.nber.org/papers/w7819}{Levinsohn-Petrin (2000)}. 4 | #' @param data A data.frame or tibble containing the variables of the model. 5 | #' @param formula An object of the class \code{\link[stats]{formula}}. 6 | #' @param exit An optional formula with the name of the variabe indicator of firm's last period. \emph{~exit}, for example. 7 | #' @param gross If TRUE dependent variable is gross output. 8 | #' @param id A character with the name of the indicator variable. 9 | #' @param time A character with the name of the time variable. 10 | #' @param bootstrap An optional logical. If TRUE calculate bootstrap standard errors. 11 | #' @param reps The number of bootstrap replications. 12 | #' @param degree A vector with the number of polynomial interactions in each stage of the routine. 13 | #' @param verify Verify if inputs are sorted. 14 | #' @param maxiter Parameter of \code{nls.lm} at second stage. 15 | #' @param ... Additional arguments. 16 | #' @details Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 17 | #' It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 18 | #' The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 19 | #' @examples 20 | #' data(estprod_data) 21 | #' levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 22 | #' exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 23 | #' @export 24 | 25 | levinsohn_petrin <- function(data, formula = y ~ free | capital | proxy | controls, exit = NULL, gross = FALSE, id = "id", time = "year", 26 | bootstrap = TRUE, reps = 2, degree = c(3, 3), verify = TRUE, maxiter = 100, ...){ 27 | 28 | formula <- Formula::Formula(formula) 29 | 30 | #----------------------------------------------------- 31 | #verify it has minimun arguments 32 | #----------------------------------------------------- 33 | if (max(length(formula)) < 3){ 34 | stop("The right hand side of the formula must constain at least the first three parts!") 35 | } 36 | if (!exists("data")){ 37 | stop("Data is missing!") 38 | } 39 | 40 | data_df <- as.data.frame(data) 41 | 42 | id <- data_df[, id] 43 | 44 | time <- data_df[, time] 45 | 46 | if (!identical(order(id, time), 1:length(id))) { 47 | if (verify) { 48 | stop("Panel not sorted.") 49 | } 50 | } 51 | 52 | called_func <- match.call() 53 | 54 | #----------------------------------------------------- 55 | #Matrizes a partir da formula_fs 56 | #----------------------------------------------------- 57 | n_length <- dim(data)[1] 58 | 59 | free <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 1)) 60 | colnames(free) <- labels(terms(formula(formula, lhs = 0, rhs = 1))) 61 | free_names <- colnames(free) 62 | 63 | capital <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 2)) 64 | colnames(capital) <- labels(terms(formula(formula, lhs = 0, rhs = 2))) 65 | capital_names <- colnames(capital) 66 | 67 | proxy <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 3)) 68 | colnames(proxy) <- labels(terms(formula(formula, lhs = 0, rhs = 3))) 69 | proxy_names <- colnames(proxy) 70 | 71 | if (length(formula)[2] == 4){ 72 | controls <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 4)) 73 | colnames(controls) <- labels(terms(formula(formula, lhs = 0, rhs = 4))) 74 | controls_names <- colnames(controls) 75 | controls_length <- dim(controls)[2] 76 | } else { 77 | #será zero para primeiro estagio funcionar 78 | controls <- as.matrix(rep(0, n_length)) 79 | controls_length <- 0 80 | controls_names <- "zero" 81 | colnames(controls) <- controls_names 82 | } 83 | 84 | 85 | y <- as.matrix(model.frame(formula, data = data, lhs = 1, rhs = 0)) 86 | 87 | 88 | k_length <- dim(capital)[2] 89 | 90 | free_length <- dim(free)[2] 91 | 92 | proxy_length <- dim(proxy)[2] 93 | 94 | 95 | 96 | 97 | ############################################ 98 | #Primeiro Estágio 99 | ############################################ 100 | 101 | #prev <- sapply(ls(), function(x) get(x), simplify = F, USE.NAMES = T) 102 | 103 | first_stage <- fs(data = data_df, y = y, free = free, capital = capital, proxy = proxy, controls = controls, exit = exit, id = id, time = time, formula = formula, degree = degree) 104 | 105 | ############################################ 106 | #Segundo Estágio 107 | ############################################ 108 | 109 | if (gross == TRUE) { 110 | second_stage <- ss_lp_gross(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, 111 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, 112 | maxiter = maxiter) 113 | } else { 114 | second_stage <- ss_lp_va(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, degree = degree, 115 | k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, 116 | maxiter = maxiter) 117 | } 118 | 119 | 120 | ############################################# 121 | #bootstrap 122 | ############################################# 123 | if (bootstrap == TRUE){ 124 | 125 | call_boot <- lazyeval::call_modify(called_func, new_args = list(data = quote(data_df), statistic = quote(boot_levinsohn_petrin), R = reps, strata = quote(id), bootstrap = FALSE)) 126 | 127 | call_boot[[1]] <- quote(boot::boot) 128 | 129 | boot_result <- eval(call_boot) 130 | 131 | boot_result[["Call"]] <- called_func 132 | 133 | boot_result[["varnames"]] <- c(free_names, 134 | capital_names, 135 | switch((gross > 0) + 1 , NULL, proxy_names), 136 | switch((controls_length > 0) + 1 , NULL, controls_names)) 137 | 138 | class(boot_result) <- c("estprod", "boot") 139 | 140 | return(boot_result) 141 | } 142 | 143 | ############################################# 144 | #No bootstrap 145 | ############################################# 146 | results <- list() 147 | 148 | results[["Call"]] <- called_func 149 | 150 | #display proxy coefficients if gross = F subtract one 151 | Coefficients <- matrix(c(beta_fs_free, 152 | ss_reg$par[1:k_length], 153 | switch((gross > 0) + 1 , NULL, ss_reg$par[(k_length + 1):(k_length + proxy_length)]), 154 | switch((controls_length > 0) + 1 , NULL, ss_reg$par[(k_length + proxy_length*gross + 1 ):(k_length + proxy_length*gross + controls_length)])), 155 | ncol = 1) 156 | 157 | rownames(Coefficients) <- c(free_names, 158 | capital_names, 159 | switch((gross > 0) + 1 , NULL, proxy_names), 160 | switch((controls_length > 0) + 1 , NULL, controls_names)) 161 | 162 | colnames(Coefficients) <- c("Estimate") 163 | 164 | 165 | results[["Coefficients"]] <- Coefficients 166 | 167 | attr(results, "class") <- c("estprod", "list") 168 | 169 | return(results) 170 | 171 | } -------------------------------------------------------------------------------- /R/olley_pakes.R: -------------------------------------------------------------------------------- 1 | utils::globalVariables(c("phi", "myprobit_lag", "beta_fs_matrix", "beta_fs_free", "beta_fs_controls", "ss_reg", "nls.lm.control")) 2 | #' @title Olley-Pakes Estimation of Production Functions 3 | #' @description This function aims the estimation of production functions using \href{https://www.jstor.org/stable/2171831?seq=1#page_scan_tab_contents}{Olley-Pakes (1996)}. 4 | #' @param data A data.frame or tibble containing the variables of the model. 5 | #' @param formula An object of the class \code{\link[stats]{formula}}. 6 | #' @param exit An optional formula with the name of the variabe indicator of firm's last period. \code{~exit}, for example. 7 | #' @param id A character with the name of the indicator variable. 8 | #' @param time A character with the name of the time variable. 9 | #' @param bootstrap An optional logical. If TRUE calculate bootstrap standard errors. 10 | #' @param reps The number of bootstrap replications. 11 | #' @param degree A vector with the number of the polynomial interactions in each stage of the routine. 12 | #' @param verify Verify if inputs are sorted. 13 | #' @param maxiter Parameter of \code{nls.lm} at second stage. 14 | #' @param ... Additional arguments. 15 | #' @details Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 16 | #' It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 17 | #' The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 18 | #' @examples data(estprod_data) 19 | #' olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, 20 | #' exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 21 | #' @export 22 | 23 | olley_pakes <- function(data, formula = y ~ free | capital | proxy | controls, exit = NULL, id = "id", time = "year", 24 | bootstrap = TRUE, reps = 2, degree = c(3, 2), verify = TRUE, maxiter = 100, ...){ 25 | 26 | formula <- Formula::Formula(formula) 27 | 28 | #----------------------------------------------------- 29 | #verify it has minimun arguments 30 | #----------------------------------------------------- 31 | if (max(length(formula)) < 3){ 32 | stop("The right hand side of the formula must constain at least the first three parts!") 33 | } 34 | if (!exists("data")){ 35 | stop("Data is missing!") 36 | } 37 | 38 | 39 | data_df <- as.data.frame(data) 40 | 41 | id <- data_df[, id] 42 | 43 | time <- data_df[, time] 44 | 45 | 46 | if (!identical(order(id, time), 1:length(id))) { 47 | if (verify) { 48 | stop("Panel not sorted.") 49 | } 50 | } 51 | 52 | 53 | called_func <- match.call() 54 | 55 | #----------------------------------------------------- 56 | #Matrizes a partir da formula_fs 57 | #----------------------------------------------------- 58 | n_length <- dim(data)[1] 59 | 60 | free <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 1)) 61 | colnames(free) <- labels(terms(formula(formula, lhs = 0, rhs = 1))) 62 | free_names <- colnames(free) 63 | 64 | capital <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 2)) 65 | colnames(capital) <- labels(terms(formula(formula, lhs = 0, rhs = 2))) 66 | capital_names <- colnames(capital) 67 | 68 | proxy <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 3)) 69 | colnames(proxy) <- labels(terms(formula(formula, lhs = 0, rhs = 3))) 70 | proxy_names <- colnames(proxy) 71 | 72 | if (length(formula)[2] == 4){ 73 | controls <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 4)) 74 | colnames(controls) <- labels(terms(formula(formula, lhs = 0, rhs = 4))) 75 | controls_names <- colnames(controls) 76 | controls_length <- dim(controls)[2] 77 | } else { 78 | #será zero para primeiro estagio funcionar 79 | controls <- as.matrix(rep(0, n_length)) 80 | controls_length <- 0 81 | controls_names <- "zero" 82 | colnames(controls) <- controls_names 83 | } 84 | 85 | 86 | y <- as.matrix(model.frame(formula, data = data, lhs = 1, rhs = 0)) 87 | 88 | 89 | k_length <- dim(capital)[2] 90 | 91 | free_length <- dim(free)[2] 92 | 93 | proxy_length <- dim(proxy)[2] 94 | 95 | 96 | 97 | 98 | ############################################ 99 | #Primeiro Estágio 100 | ############################################ 101 | 102 | first_stage <- fs(data = data_df, y = y, free = free, capital = capital, proxy = proxy, controls = controls, exit = exit, id = id, time = time, formula = formula, degree = degree) 103 | 104 | ############################################ 105 | #Segundo Estágio 106 | ############################################ 107 | 108 | second_stage <- ss_op(y = y, free = free, capital = capital, proxy = proxy, controls = controls, id = id, time = time, phi = phi, myprobit_lag = myprobit_lag, 109 | degree = degree, k_length = k_length, proxy_length = proxy_length, controls_length = controls_length, 110 | beta_fs_matrix = beta_fs_matrix, beta_fs_free = beta_fs_free, beta_fs_controls = beta_fs_controls, maxiter = maxiter) 111 | 112 | ############################################# 113 | #bootstrap 114 | ############################################# 115 | if (bootstrap == TRUE){ 116 | 117 | call_boot <- lazyeval::call_modify(called_func, new_args = list(data = quote(data_df), statistic = quote(boot_olley_pakes), R = reps, strata = quote(id), bootstrap = FALSE)) 118 | 119 | call_boot[[1]] <- quote(boot::boot) 120 | 121 | boot_result <- eval(call_boot) 122 | 123 | boot_result[["Call"]] <- called_func 124 | 125 | boot_result[["varnames"]] <- c(free_names, 126 | capital_names, 127 | switch((controls_length > 0) + 1 , NULL, controls_names)) 128 | 129 | class(boot_result) <- c("estprod", "boot") 130 | 131 | return(boot_result) 132 | } 133 | 134 | #----------------------------------------------------- 135 | #Results without bootstrap 136 | #----------------------------------------------------- 137 | 138 | results <- list() 139 | 140 | results[["Call"]] <- called_func 141 | 142 | Coefficients <- matrix(c(beta_fs_free, 143 | ss_reg$par[2:(k_length + 1)], 144 | switch((controls_length > 0) +1 , NULL, beta_fs_controls)), ncol = 1) 145 | 146 | rownames(Coefficients) <- c(free_names, 147 | capital_names, 148 | switch((controls_length > 0) + 1 , NULL, controls_names)) 149 | 150 | colnames(Coefficients) <- c("Estimate") 151 | 152 | results[["Coefficients"]] <- Coefficients 153 | 154 | attr(results, "class") <- c("estprod", "list") 155 | 156 | return(results) 157 | 158 | } -------------------------------------------------------------------------------- /R/panel_lag.R: -------------------------------------------------------------------------------- 1 | #' @title Panel data lag function 2 | #' @description This function aims create the lags of a specified variable from panel data. 3 | #' @param x A vector, data.frame, tibble or matrix. 4 | #' @param id A character with the name of the indicator variable. 5 | #' @param time A character with the name of the time variable. 6 | #' @param lag Number of lags. 7 | #' @param verify Check if panel is sorted by id and time variables. 8 | #' @note Based on \href{https://bitbucket.org/paulschrimpf/}{Paul Schrimpf's} lag function. 9 | #' @export 10 | #' 11 | panel_lag <- function(x, id, time, lag = 1, verify = TRUE) { 12 | 13 | #se for tibble preciso converter elementos em vetores 14 | if (any(class(x) == "tbl")) { 15 | x <- as.data.frame(x) 16 | } 17 | if (!identical(order(id, time), 1:length(id)) & verify) { 18 | stop("inputs not sorted.") 19 | } 20 | if (is.matrix(x)) { 21 | return(apply(x, MARGIN=2, FUN=function(c) { panel_lag(c, id, time, lag, verify) })) 22 | } 23 | if (length(id) != length(x) || length(id) != length(time) ) { 24 | stop("Inputs not same length") 25 | } 26 | if (lag>0) { 27 | x.lag <- x[1:(length(x) - lag)] 28 | x.lag[id[1:(length(id) - lag)]!=id[(1 + lag):length(id)] ] <- NA 29 | x.lag[time[1:(length(id) - lag) + lag] !=time[(1 + lag):length(id)] ] <- NA 30 | return(c(rep(NA, lag), x.lag)) 31 | } else if (lag<0) { 32 | lag <- abs(lag) 33 | x.lag <- x[(1 + lag):length(x)] 34 | x.lag[id[1:(length(id) - lag)]!=id[(1 + lag):length(id)] ] <- NA 35 | x.lag[time[1:(length(id) - lag) + lag]!=time[(1 + lag):length(id)] ] <- NA 36 | return(c(x.lag, rep(NA, lag))) 37 | } else { # lag=0 38 | return (x) 39 | } 40 | } -------------------------------------------------------------------------------- /R/poly_elements.R: -------------------------------------------------------------------------------- 1 | #' @title Number of \code{poly} elements. 2 | #' @description This function aims calculate the number of terms of a polynomial interactions. 3 | #' @param n The number of variables. 4 | #' @param d Degreess of polynomial interaction. 5 | #' @export 6 | poly_elements <- function (n, d) { 7 | if (d < 1) return(0) 8 | component <- sapply(1:d, interactions, n = n) 9 | list(component = component, ncol = sum(component)) 10 | } -------------------------------------------------------------------------------- /R/poly_name.R: -------------------------------------------------------------------------------- 1 | m <- matrix(c(1:10), dimnames = list(NULL, c("var2","var3")), nrow = 5) 2 | 3 | m_poly <- poly(m, degree = 2, raw = T) * 1/2 4 | 5 | #m_poly <- m_poly[,seq(attr(m_poly, "degree"))[attr(m_poly, "degree") > 1]] 6 | 7 | 8 | poly_name <- function(poly_data, original_data, sep = "_"){ 9 | #x: original poly names 10 | x <- colnames(poly_data) 11 | 12 | #y: original var names 13 | if (class(original_data) %in% c("data.frame", "tbl", "matrix")) { 14 | y <- colnames(original_data) 15 | }else { 16 | y <- original_data 17 | } 18 | 19 | 20 | #x_xtable: table with the names of x: each column one var. Each line: number of times in taht interaction 21 | x_table <- read.table(text = x, sep = ".") 22 | 23 | if (length(y) != ncol(x_table)) stop("Number of variables not the same!") 24 | 25 | 26 | 27 | colnames(x_table) <- y 28 | 29 | #for each column 30 | for (column in 1:ncol(x_table)) { 31 | 32 | #replace in each column: concatenates each line text (all cells) repeated by the number of each cell 33 | x_table[column] <- sapply(1:nrow(x_table), function(i) paste0(rep(colnames(x_table[column]), x_table[i,column]), collapse = sep)) 34 | 35 | } 36 | 37 | 38 | #concatanate each line of x_table and cleans 39 | new_names <- matrix() 40 | for (i in 1:nrow(x_table)){ 41 | new_names[i] <- paste0(x_table[i,x_table[i,] != ""], collapse = sep) 42 | } 43 | 44 | return(new_names) 45 | 46 | } 47 | 48 | poly_name(m_poly, m) 49 | 50 | m_poly 51 | -------------------------------------------------------------------------------- /R/print.estprod.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | print.estprod <- function(x, ...){ 3 | 4 | #----------------------------------------------------- 5 | #Results with and without bootstrap 6 | #----------------------------------------------------- 7 | 8 | results <- list() 9 | 10 | if (any(class(x) == "boot")) { 11 | 12 | results[["Call"]] <- x$Call 13 | 14 | se <- apply(x$t, 2, function(z) sqrt(var(z))) 15 | 16 | #lower.tail = FALSE = 2*(1-pnorm()) 17 | Coefficients <- cbind(Estimate = x$t0, `Std. Error` = se, 18 | `z value` = x$t0/se, `Pr(>|z|)` = 2 * pnorm(abs(x$t0/se), lower.tail = FALSE)) 19 | 20 | Coefficients <- Coefficients[1:length(x$varnames),] #filtra para não icluir termos do polinomio 21 | 22 | rownames(Coefficients) <- x$varnames 23 | 24 | results[["Coefficients"]] <- Coefficients 25 | 26 | 27 | } else { 28 | results <- x 29 | } 30 | 31 | if (results$Call[[1]] == "levinsoh_petrin") { 32 | cat("Levinsoh-Petrin Production Function Estimator\n\n") 33 | } else if (results$Call[[1]] == "olley_pakes") { 34 | cat("Olley-Pakes Production Function Estimator\n\n") 35 | } else if (results$Call[[1]] == "wooldridge") { 36 | cat("Wooldridge Production Function Estimator\n\n") 37 | } 38 | 39 | class(results) <- "list" 40 | 41 | cat("Call\n") 42 | print(results[["Call"]]) 43 | cat("\n") 44 | 45 | cat("Coefficients\n") 46 | printCoefmat(results[["Coefficients"]]) 47 | cat("\n") 48 | 49 | if (any(class(x) == "boot")) { 50 | cat("#Bootstraped standard errors.") 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /R/ss_lp_gross.R: -------------------------------------------------------------------------------- 1 | ss_lp_gross <- function(y, free, capital, proxy, controls, id, time, phi, myprobit_lag, k_length, proxy_length, controls_length, beta_fs_matrix, beta_fs_free, maxiter = 1000, ...) { 2 | 3 | #----------------------------------------------------- 4 | #Segundo estágio (ss) gross 5 | #----------------------------------------------------- 6 | #tenho q editar se tiver mais d um capital 7 | 8 | capital_lag <- panel_lag(capital, id, time, verify = FALSE) 9 | colnames(capital_lag) <- paste0("lag_", colnames(capital_lag)) 10 | names_capital_lag <- colnames(capital_lag) 11 | 12 | controls_lag <- panel_lag(controls, id, time, verify = FALSE) 13 | colnames(controls_lag) <- paste0("lag_", colnames(controls_lag)) 14 | names_controls_lag <- colnames(controls_lag) 15 | 16 | free_lag <- panel_lag(free, id, time, verify = FALSE) 17 | colnames(free_lag) <- paste0("lag_", colnames(free_lag)) 18 | names_free_lag <- colnames(free_lag) 19 | 20 | proxy_lag <- panel_lag(proxy, id, time, verify = FALSE) 21 | colnames(proxy_lag) <- paste0("lag_", colnames(proxy_lag)) 22 | names_proxy_lag <- colnames(proxy_lag) 23 | 24 | proxy_2_lag <- panel_lag(proxy_lag, id, time, verify = FALSE) 25 | colnames(proxy_2_lag) <- paste0("lag_", colnames(proxy_lag)) 26 | names_proxy_2_lag <- colnames(proxy_2_lag) 27 | 28 | inst_names <- c(names_free_lag, names_proxy_lag, names_proxy_2_lag, names_capital_lag, colnames(capital)) 29 | 30 | 31 | df_ss <- cbind(y = c(y), 32 | free, 33 | capital, 34 | capital_lag, 35 | phi = c(phi), 36 | phi_lag = c(panel_lag(phi, id, time, verify = FALSE)), 37 | controls, 38 | controls_lag, 39 | free_lag, 40 | proxy, 41 | proxy_lag, 42 | proxy_2_lag) 43 | 44 | df_ss <- df_ss[complete.cases(df_ss[, "phi_lag"]),] 45 | 46 | #rm(phi, free, capital, capital_lag, controls_lag, free_lag, proxy_lag, proxy_2_lag) 47 | 48 | #objective function = sum of residuals ^2 49 | objective <- function(start, data_ss = df_ss) { 50 | 51 | #constante: primeira variável. beta_k: (1 + 1) até o numero de k + 1 52 | #beta_poly: as demais 53 | 54 | beta_k <- start[1:k_length] 55 | beta_ss_proxy <- start[(k_length + 1):(k_length + proxy_length)] 56 | beta_ss_controls <- start[-1:-(k_length + proxy_length)] 57 | 58 | #omega = phi - beta_k * k 59 | data_ss <- cbind(data_ss, 60 | res = c(data_ss[, "y"] - beta_fs_matrix[[1]] - data_ss[, colnames(free)] %*% as.matrix(beta_fs_free) - data_ss[, colnames(capital)] %*% as.matrix(beta_k) - data_ss[, colnames(proxy)] %*% as.matrix(beta_ss_proxy) - data_ss[, colnames(controls)] %*% as.matrix(beta_ss_controls)), 61 | lag_omega = c(data_ss[, "phi_lag"] - data_ss[, names_capital_lag] %*% as.matrix(beta_k) - data_ss[, names_proxy_lag] %*% as.matrix(beta_ss_proxy) - data_ss[, names_controls_lag] %*% as.matrix(beta_ss_controls))) 62 | 63 | 64 | omega_qr <- qr(data_ss[, "lag_omega"]) 65 | omega_hat <- qr.fitted(omega_qr, data_ss[, "res"]) 66 | 67 | data_ss <- as.matrix(data_ss) 68 | 69 | 70 | lp <- c(data_ss[, "res"] - omega_hat) 71 | 72 | lp <- colSums(data_ss[, inst_names] * lp, na.rm = TRUE) 73 | 74 | return(lp) 75 | } 76 | 77 | 78 | #n_start = n_capital 79 | start <- rep(0, (k_length + switch((controls_length > 0) + 1 , 1, controls_length) + proxy_length)) 80 | 81 | ss_reg <- minpack.lm::nls.lm(par = start, fn = objective, control = minpack.lm::nls.lm.control(maxiter = maxiter, nprint = 0)) 82 | 83 | assign("ss_reg", ss_reg, envir = parent.frame()) 84 | } -------------------------------------------------------------------------------- /R/ss_lp_va.R: -------------------------------------------------------------------------------- 1 | ss_lp_va <- function(y, free, capital, proxy, controls, id, time, phi, myprobit_lag, degree, k_length, proxy_length, controls_length, beta_fs_matrix, beta_fs_free, maxiter, ...) { 2 | #----------------------------------------------------- 3 | #Segundo estágio (ss) valor adicionad 4 | #----------------------------------------------------- 5 | 6 | capital_lag = panel_lag(capital, id, time, verify = FALSE) 7 | colnames(capital_lag) <- paste0("lag_", colnames(capital_lag)) 8 | names_capital_lag <- colnames(capital_lag) 9 | 10 | controls_lag = panel_lag(controls, id, time, verify = FALSE) 11 | colnames(controls_lag) <- paste0("lag_", colnames(controls)) 12 | names_controls_lag <- colnames(controls_lag) 13 | 14 | df_ss <- cbind(y_ss = c(y), 15 | free, 16 | capital, 17 | capital_lag, 18 | phi = c(phi), 19 | phi_lag = c(panel_lag(phi, id, time, verify = FALSE)), 20 | controls, 21 | controls_lag) 22 | 23 | df_ss <- df_ss[complete.cases(df_ss),] 24 | 25 | #rm(phi, capital_lag, controls_lag) 26 | 27 | #objective function = sum of residuals ^2 28 | objective <- function(start, data_ss = df_ss) { 29 | #constante: primeira variável. beta_k: (1 + 1) até o numero de k + 1 30 | #beta_poly: as demais 31 | 32 | beta_k <- start[1:k_length] 33 | beta_ss_controls <- start[-1:-k_length] 34 | 35 | data_ss <- as.matrix(data_ss) 36 | 37 | #omega = phi - beta_k * k 38 | data_ss <- cbind(data_ss, 39 | omega = c(data_ss[, "phi"] - as.matrix(data_ss[, colnames(capital)]) %*% as.matrix(beta_k) - data_ss[, colnames(controls)] %*% as.matrix(beta_ss_controls)), 40 | lag_omega = c(data_ss[, "phi_lag"] - data_ss[, names_capital_lag] %*% as.matrix(beta_k) - data_ss[, names_controls_lag] %*% as.matrix(beta_ss_controls))) 41 | 42 | 43 | omega_pol <- cbind(const = 1, poly(cbind(data_ss[, "lag_omega"], myprobit_lag), degree = degree[2])) 44 | 45 | 46 | omega_pol <- qr(omega_pol) 47 | omega_hat <- qr.fitted(omega_pol, data_ss[, "omega"]) 48 | 49 | data_ss <- as.matrix(data_ss) 50 | 51 | lp <- data_ss[, colnames(free)] %*% as.matrix(beta_fs_free) + data_ss[, colnames(capital)] %*% as.matrix(beta_k) + data_ss[, colnames(controls)] %*% as.matrix(beta_ss_controls) + as.matrix(omega_hat) 52 | lp <- (data_ss[, 1] - lp) 53 | 54 | 55 | return(lp) 56 | 57 | } 58 | 59 | #n_start = n_capital 60 | start <- rep(0, (k_length + switch((controls_length > 0) + 1 , 1, controls_length))) 61 | 62 | ss_reg <- minpack.lm::nls.lm(par = start, fn = objective, control = minpack.lm::nls.lm.control(maxiter = maxiter, nprint = 0)) 63 | 64 | assign("ss_reg", ss_reg, envir = parent.frame()) 65 | 66 | } -------------------------------------------------------------------------------- /R/ss_op.R: -------------------------------------------------------------------------------- 1 | ss_op <- function(y, free, capital, proxy, controls, id, time, phi, myprobit_lag, degree, k_length, proxy_length, controls_length, beta_fs_matrix, beta_fs_free, beta_fs_controls, maxiter, ...){ 2 | 3 | #----------------------------------------------------- 4 | #Segundo estágio (ss) 5 | #----------------------------------------------------- 6 | 7 | capital_lag = panel_lag(capital, id, time, verify = FALSE) 8 | 9 | names_capital_lag <- paste0("lag_", colnames(capital_lag)) 10 | 11 | colnames(capital_lag) <- names_capital_lag 12 | 13 | df_ss <- data.frame(y_ss = c(y - free %*% beta_fs_free - controls %*% beta_fs_controls - beta_fs_matrix[1]), 14 | free, 15 | capital, 16 | capital_lag, 17 | phi = c(phi), 18 | phi_lag = c(panel_lag(phi, id, time, verify = FALSE)), 19 | controls) 20 | 21 | df_ss <- df_ss[complete.cases(df_ss),] 22 | 23 | #rm(phi, capital_lag) 24 | 25 | #objective function = sum of residuals ^2 26 | objective <- function(start, data_ss = df_ss) { 27 | 28 | data_ss <- as.matrix(data_ss) 29 | 30 | #constante: primeira variável. beta_k: (1 + 1) até o numero de k + 1 31 | #beta_poly: as demais 32 | beta_const <- start[1] 33 | beta_k <- start[2:(k_length + 1)] 34 | beta_poly <- start[-(1:(k_length + 1))] 35 | 36 | 37 | poly_df <- cbind(omega = data_ss[, "phi_lag"] - data_ss[, names_capital_lag] %*% as.matrix(beta_k), myprobit_lag) 38 | 39 | poly_df <- poly(poly_df, degree = degree[2], raw = TRUE) 40 | 41 | poly_df <- poly_df %*% diag(beta_poly, nrow = length(beta_poly)) 42 | 43 | op <- qr(cbind(const = 1 * beta_const, poly_df)) 44 | 45 | op <- qr.resid(op, data_ss[, "y_ss"] - data_ss[, colnames(capital)] %*% as.matrix(beta_k)) 46 | 47 | return(op) 48 | #return(sum(op^2)) 49 | 50 | } 51 | 52 | #n_start = n_capital + n_const + n_interactions 53 | with_exit <- ifelse(!is.null(myprobit_lag), 1, 0) 54 | n_start <- k_length + 1 + poly_elements(k_length + with_exit, d = degree[2])[[2]] 55 | 56 | start <- rep(.2624996, n_start) 57 | 58 | 59 | ss_reg <- minpack.lm::nls.lm(par = start, fn = objective, control = minpack.lm::nls.lm.control(maxiter = maxiter, nprint = 0)) 60 | #ss_reg <- optimx::optimx(par = start, fn = objective, method = c('Nelder-Mead', 'BFGS', 'CG', 'L-BFGS-B', 'nlm', 61 | # 'nlminb', 'spg', 'ucminf', 'newuoa', 'bobyqa', 'nmkb', 'hjkb', 'Rcgmin', 'Rvmmin'), itnmax = 100, control = list(ndeps = 1e-6)) 62 | #print(ss_reg) 63 | 64 | assign("ss_reg", ss_reg, envir = parent.frame()) 65 | 66 | } 67 | -------------------------------------------------------------------------------- /R/summary.estprod.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | summary.estprod <- function(object, ...) { 3 | print(object) 4 | } 5 | -------------------------------------------------------------------------------- /R/wooldridge.R: -------------------------------------------------------------------------------- 1 | utils::globalVariables(c("phi", "myprobit_lag", "beta_fs_matrix", "beta_fs_free", "beta_fs_controls", "ss_reg", "nls.lm.control")) 2 | #' @title Wooldridge Estimation of Production Functions (Cobb-Douglas) 3 | #' @description This function aims the estimation of Cobb-Douglas production functions using \href{https://doi.org/10.1016/j.econlet.2009.04.026}{Wooldridge (2009)} method. 4 | #' @param data A data.frame or tibble containing the variables of the model. 5 | #' @param formula An object of the class \code{\link[stats]{formula}}. 6 | #' @param gross If TRUE dependent variable is gross output. 7 | #' @param id A character with the name of the indicator variable. 8 | #' @param time A character with the name of the time variable. 9 | #' @param bootstrap An optional logical. If TRUE calculate bootstrap standard errors. 10 | #' @param reps The number of bootstrap replications. 11 | #' @param degree A vector with the number of the polynomial interactions in each stage of the routine. 12 | #' @param verify Verify if inputs are sorted. 13 | #' @param ... Additional arguments. 14 | #' @details Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 15 | #' It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 16 | #' The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 17 | #' @examples data(estprod_data) 18 | #' wooldridge(data = estprod_data, var1 ~ var2 | var3 | var4, 19 | #' id = "id", time = "year", bootstrap = TRUE) 20 | #' @export 21 | 22 | wooldridge <- function(data, formula = y ~ free | capital | proxy | controls, gross = FALSE, id = "id", time = "year", 23 | bootstrap = FALSE, reps = 2, degree = c(3, 2), verify = TRUE, ...){ 24 | 25 | formula <- Formula::Formula(formula) 26 | 27 | #----------------------------------------------------- 28 | #verify it has minimun arguments 29 | #----------------------------------------------------- 30 | if (max(length(formula)) < 3){ 31 | stop("The right hand side of the formula must constain at least the first three parts!") 32 | } 33 | if (!exists("data")){ 34 | stop("Data is missing!") 35 | } 36 | 37 | 38 | data_df <- as.data.frame(data) 39 | 40 | id <- data_df[, id] 41 | 42 | time <- data_df[, time] 43 | 44 | 45 | if (!identical(order(id, time), 1:length(id))) { 46 | if (verify) { 47 | stop("Panel not sorted.") 48 | } 49 | } 50 | 51 | 52 | called_func <- match.call() 53 | 54 | #----------------------------------------------------- 55 | #Matrizes a partir da formula_fs 56 | #----------------------------------------------------- 57 | n_length <- dim(data)[1] 58 | 59 | free <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 1)) 60 | colnames(free) <- labels(terms(formula(formula, lhs = 0, rhs = 1))) 61 | free_names <- colnames(free) 62 | 63 | capital <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 2)) 64 | colnames(capital) <- labels(terms(formula(formula, lhs = 0, rhs = 2))) 65 | capital_names <- colnames(capital) 66 | 67 | proxy <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 3)) 68 | colnames(proxy) <- labels(terms(formula(formula, lhs = 0, rhs = 3))) 69 | proxy_names <- colnames(proxy) 70 | 71 | if (length(formula)[2] == 4){ 72 | controls <- as.matrix(model.frame(formula, data = data, lhs = 0, rhs = 4)) 73 | colnames(controls) <- labels(terms(formula(formula, lhs = 0, rhs = 4))) 74 | controls_names <- colnames(controls) 75 | controls_length <- dim(controls)[2] 76 | 77 | if (any(controls_names == "Null")){ 78 | stop("Controls names can not be 'Null', it's a reserved word.") 79 | } 80 | 81 | } else { 82 | #será zero para primeiro estagio funcionar 83 | controls <- as.matrix(rep(0, n_length)) 84 | controls_length <- 0 85 | controls_names <- "Null" 86 | colnames(controls) <- controls_names 87 | } 88 | 89 | 90 | y <- as.matrix(model.frame(formula, data = data, lhs = 1, rhs = 0)) 91 | 92 | 93 | k_length <- dim(capital)[2] 94 | 95 | free_length <- dim(free)[2] 96 | 97 | proxy_length <- dim(proxy)[2] 98 | 99 | 100 | ############################################ 101 | #Wooldridgw specific matrix 102 | ############################################ 103 | 104 | free_lag <- panel_lag(free, id, time, 1, verify = F) 105 | 106 | colnames(free_lag) <- paste0("lag_", colnames(free)) 107 | 108 | free_lag_names <- colnames(free_lag) 109 | 110 | 111 | 112 | interaction_vars <- poly(cbind(capital, proxy), degree = degree[1]) 113 | 114 | interaction_vars <- interaction_vars[,seq(attr(interaction_vars, "degree"))[attr(interaction_vars, "degree") > 1]] 115 | 116 | interactions_length <- dim(interaction_vars)[2] 117 | 118 | colnames(interaction_vars) <- paste0("inter_", colnames(interaction_vars)) 119 | 120 | interaction_vars_names <- colnames(interaction_vars) 121 | 122 | 123 | 124 | 125 | interaction_lag_vars <- panel_lag(interaction_vars, id = id, time = time, verify = F) 126 | 127 | interaction_lag_length <- dim(interaction_lag_vars)[2] 128 | 129 | colnames(interaction_lag_vars) <- paste0("lag_", colnames(interaction_lag_vars)) 130 | 131 | interaction_lag_vars_names <- colnames(interaction_lag_vars) 132 | 133 | 134 | y_name <- colnames(y) 135 | 136 | 137 | df_ss <- cbind(y, free, free_lag, proxy, capital, controls, interaction_vars, interaction_lag_vars) 138 | 139 | df_ss <- df_ss[complete.cases(df_ss),] 140 | 141 | 142 | 143 | ############################################ 144 | #GMM 145 | ############################################ 146 | 147 | if (controls_names == "Null") { 148 | eq1 <- as.formula(paste0(y_name, "~", paste0(c(free_names, capital_names, interaction_vars_names), collapse = "+"))) 149 | 150 | eq2 <- as.formula(paste0(y_name, "~", paste0(c(free_names, capital_names, interaction_lag_vars_names), collapse = "+"))) 151 | 152 | eq_list <- list(eq1, eq2) 153 | 154 | z_list <- list(as.formula(paste( "~ ", paste0(c(free_names, capital_names, interaction_vars_names), collapse = "+"))), 155 | as.formula(paste( "~ ", paste0(c(free_lag_names, capital_names, interaction_lag_vars_names), collapse = "+")))) 156 | 157 | } else if (controls_names != "Null") { 158 | 159 | eq1 <- as.formula(paste0(y_name, "~", paste0(c(free_names, capital_names, controls_names, interaction_vars_names), collapse = "+"))) 160 | 161 | eq2 <- as.formula(paste0(y_name, "~", paste0(c(free_names, capital_names, controls_names, interaction_lag_vars_names), collapse = "+"))) 162 | 163 | eq_list <- list(eq1, eq2) 164 | 165 | z_list <- list(as.formula(paste( "~ ", paste0(c(free_names, capital_names, controls_names, interaction_vars_names), collapse = "+"))), 166 | as.formula(paste( "~ ", paste0(c(free_lag_names, capital_names, controls_names, interaction_lag_vars_names), collapse = "+")))) 167 | 168 | } else { 169 | stop("Some error occured!") 170 | } 171 | 172 | woold <- gmm::sysGmm(eq_list, z_list, data = as.data.frame(df_ss), crossEquConst = (2):(1 + free_length + k_length + controls_length)) 173 | 174 | 175 | ############################################# 176 | #bootstrap 177 | ############################################# 178 | if (bootstrap == TRUE){ 179 | 180 | call_boot <- lazyeval::call_modify(called_func, new_args = list(data = quote(data_df), statistic = quote(boot_wooldridge), R = reps, strata = quote(id), bootstrap = FALSE)) 181 | 182 | call_boot[[1]] <- quote(boot::boot) 183 | 184 | boot_result <- eval(call_boot) 185 | 186 | boot_result[["Call"]] <- called_func 187 | 188 | boot_result[["varnames"]] <- c(free_names, 189 | capital_names, 190 | switch((controls_length > 0) + 1 , NULL, controls_names)) 191 | 192 | class(boot_result) <- c("estprod", "boot") 193 | 194 | return(boot_result) 195 | } 196 | 197 | ############################################# 198 | #Without bootstrap 199 | ############################################# 200 | 201 | results <- list() 202 | 203 | woold <- summary(woold) 204 | 205 | 206 | results[["Call"]] <- called_func 207 | 208 | results[["gmm_coefficients"]] <- woold[["coefficients"]] 209 | 210 | 211 | 212 | Coefficients <- woold[["coefficients"]][[1]][2:(1 + free_length + k_length + controls_length),] 213 | 214 | results[["Coefficients"]] <- Coefficients 215 | 216 | 217 | 218 | attr(results, "class") <- c("estprod", "list") 219 | 220 | return(results) 221 | 222 | 223 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | estprod 2 | ========== 3 | 4 | [![Build Status](https://travis-ci.org/rrremedio/estprod.svg?branch=master)](https://travis-ci.org/rrremedio/estprod) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/estprod)](https://cran.r-project.org/package=estprod) 5 | [![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/estprod)](https://cran.r-project.org/package=estprod) 6 | 7 | Estimation of production functions by the Olley-Pakes, Levinsohn-Petrin and Wooldridge methodologies. 8 | 9 | Getting Started 10 | --------------- 11 | 12 | Basic syntax is formed by a multipart formula which must be specified in the following order (additional controls are optional): 13 | 14 | ```R 15 | olley_pakes(data = estprod_data, y ~ free | capital | proxy | controls, exit = ~exit, id = "id", time = "year", bootstrap = TRUE, reps =2) 16 | 17 | levinsohn_petrin(data = estprod_data, y ~ free | capital | proxy | controls, exit = ~exit, id = "id", time = "year", bootstrap = TRUE, reps = 2, gross = FALSE) 18 | 19 | wooldridge(data = estprod_data, y ~ free | capital | proxy | controls, id = "id", time = "year", bootstrap = TRUE) 20 | ``` 21 | 22 | - ```id``` and ```time``` are panel dimensions parameters. 23 | 24 | - ```exit``` is an optional formula indicator of the last firm's period. 25 | 26 | - ```bootstrap``` is logical indicating if bootstraped standard errors should be calculated. 27 | 28 | - ```reps``` is number of bootstrap replications. 29 | 30 | - ```gross``` is a logical which indicates if dependent variable is gross output. Only in ```levinsohn_petrin```. 31 | 32 | Installing 33 | -------- 34 | - The latest released version from [CRAN](https://CRAN.R-project.org/package=estprod) with 35 | 36 | ```R 37 | install.packages("estprod") 38 | ``` 39 | - The current version from [github](https://github.com/rrremedio/estprod) with 40 | 41 | ```R 42 | devtools::install_github("rrremedio/estprod") 43 | ``` 44 | Authors 45 | -------- 46 | Rodrigo R Remédio 47 | 48 | License 49 | -------- 50 | 51 | This project is licensed under the GPL-3. 52 | -------------------------------------------------------------------------------- /data/estprod_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rrremedio/estprod/16738dac66e6a2ccb6f40c6e02d4f5ef393bd0b5/data/estprod_data.rda -------------------------------------------------------------------------------- /man/estprod_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/estprod_data.R 3 | \docType{data} 4 | \name{estprod_data} 5 | \alias{estprod_data} 6 | \title{10000 randomly generated variables in panel data format.} 7 | \format{A data frame with 10000 rows and 10 variables: 8 | \describe{ 9 | \item{id}{Identifies the 1000 randomly generated individuals.} 10 | \item{year}{The year associated to each individual observation.} 11 | \item{g1}{Put individuals in 25 groups.} 12 | \item{g2}{Put individuals in 50 groups.} 13 | \item{var1}{Randomly generated variable.} 14 | \item{var2}{Randomly generated variable.} 15 | \item{var3}{Randomly generated variable.} 16 | \item{var4}{Randomly generated variable.} 17 | \item{var5}{Randomly generated variable.} 18 | \item{exit}{The last year an id appears.} 19 | }} 20 | \usage{ 21 | estprod_data 22 | } 23 | \description{ 24 | 10000 randomly generated variables in panel data format. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/interactions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interactions.R 3 | \name{interactions} 4 | \alias{interactions} 5 | \title{Total number of \code{poly} elements.} 6 | \usage{ 7 | interactions(n, d) 8 | } 9 | \arguments{ 10 | \item{n}{The number of variables.} 11 | 12 | \item{d}{Degreess of the polynomial interaction.} 13 | } 14 | \description{ 15 | This function aims calculates the total number of terms of a polynomial interactions. 16 | } 17 | -------------------------------------------------------------------------------- /man/levinsohn_petrin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/levinsohn_petrin.R 3 | \name{levinsohn_petrin} 4 | \alias{levinsohn_petrin} 5 | \title{Levinsohn-Petrin Estimation of Production Functions} 6 | \usage{ 7 | levinsohn_petrin(data, formula = y ~ free | capital | proxy | controls, 8 | exit = NULL, gross = FALSE, id = "id", time = "year", 9 | bootstrap = TRUE, reps = 2, degree = c(3, 3), verify = TRUE, 10 | maxiter = 100, ...) 11 | } 12 | \arguments{ 13 | \item{data}{A data.frame or tibble containing the variables of the model.} 14 | 15 | \item{formula}{An object of the class \code{\link[stats]{formula}}.} 16 | 17 | \item{exit}{An optional formula with the name of the variabe indicator of firm's last period. \emph{~exit}, for example.} 18 | 19 | \item{gross}{If TRUE dependent variable is gross output.} 20 | 21 | \item{id}{A character with the name of the indicator variable.} 22 | 23 | \item{time}{A character with the name of the time variable.} 24 | 25 | \item{bootstrap}{An optional logical. If TRUE calculate bootstrap standard errors.} 26 | 27 | \item{reps}{The number of bootstrap replications.} 28 | 29 | \item{degree}{A vector with the number of polynomial interactions in each stage of the routine.} 30 | 31 | \item{verify}{Verify if inputs are sorted.} 32 | 33 | \item{maxiter}{Parameter of \code{nls.lm} at second stage.} 34 | 35 | \item{...}{Additional arguments.} 36 | } 37 | \description{ 38 | This function aims the estimation of production functions using \href{http://www.nber.org/papers/w7819}{Levinsohn-Petrin (2000)}. 39 | } 40 | \details{ 41 | Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 42 | It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 43 | The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 44 | } 45 | \examples{ 46 | data(estprod_data) 47 | levinsohn_petrin(data = estprod_data, var1 ~ var2 | var3 | var4, 48 | exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 49 | } 50 | -------------------------------------------------------------------------------- /man/olley_pakes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/olley_pakes.R 3 | \name{olley_pakes} 4 | \alias{olley_pakes} 5 | \title{Olley-Pakes Estimation of Production Functions} 6 | \usage{ 7 | olley_pakes(data, formula = y ~ free | capital | proxy | controls, 8 | exit = NULL, id = "id", time = "year", bootstrap = TRUE, reps = 2, 9 | degree = c(3, 2), verify = TRUE, maxiter = 100, ...) 10 | } 11 | \arguments{ 12 | \item{data}{A data.frame or tibble containing the variables of the model.} 13 | 14 | \item{formula}{An object of the class \code{\link[stats]{formula}}.} 15 | 16 | \item{exit}{An optional formula with the name of the variabe indicator of firm's last period. \code{~exit}, for example.} 17 | 18 | \item{id}{A character with the name of the indicator variable.} 19 | 20 | \item{time}{A character with the name of the time variable.} 21 | 22 | \item{bootstrap}{An optional logical. If TRUE calculate bootstrap standard errors.} 23 | 24 | \item{reps}{The number of bootstrap replications.} 25 | 26 | \item{degree}{A vector with the number of the polynomial interactions in each stage of the routine.} 27 | 28 | \item{verify}{Verify if inputs are sorted.} 29 | 30 | \item{maxiter}{Parameter of \code{nls.lm} at second stage.} 31 | 32 | \item{...}{Additional arguments.} 33 | } 34 | \description{ 35 | This function aims the estimation of production functions using \href{https://www.jstor.org/stable/2171831?seq=1#page_scan_tab_contents}{Olley-Pakes (1996)}. 36 | } 37 | \details{ 38 | Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 39 | It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 40 | The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 41 | } 42 | \examples{ 43 | data(estprod_data) 44 | olley_pakes(data = estprod_data, var1 ~ var2 | var3 | var4, 45 | exit = ~exit, id = "id", time = "year", bootstrap = TRUE) 46 | } 47 | -------------------------------------------------------------------------------- /man/panel_lag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/panel_lag.R 3 | \name{panel_lag} 4 | \alias{panel_lag} 5 | \title{Panel data lag function} 6 | \usage{ 7 | panel_lag(x, id, time, lag = 1, verify = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{A vector, data.frame, tibble or matrix.} 11 | 12 | \item{id}{A character with the name of the indicator variable.} 13 | 14 | \item{time}{A character with the name of the time variable.} 15 | 16 | \item{lag}{Number of lags.} 17 | 18 | \item{verify}{Check if panel is sorted by id and time variables.} 19 | } 20 | \description{ 21 | This function aims create the lags of a specified variable from panel data. 22 | } 23 | \note{ 24 | Based on \href{https://bitbucket.org/paulschrimpf/}{Paul Schrimpf's} lag function. 25 | } 26 | -------------------------------------------------------------------------------- /man/poly_elements.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/poly_elements.R 3 | \name{poly_elements} 4 | \alias{poly_elements} 5 | \title{Number of \code{poly} elements.} 6 | \usage{ 7 | poly_elements(n, d) 8 | } 9 | \arguments{ 10 | \item{n}{The number of variables.} 11 | 12 | \item{d}{Degreess of polynomial interaction.} 13 | } 14 | \description{ 15 | This function aims calculate the number of terms of a polynomial interactions. 16 | } 17 | -------------------------------------------------------------------------------- /man/wooldridge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wooldridge.R 3 | \name{wooldridge} 4 | \alias{wooldridge} 5 | \title{Wooldridge Estimation of Production Functions (Cobb-Douglas)} 6 | \usage{ 7 | wooldridge(data, formula = y ~ free | capital | proxy | controls, 8 | gross = FALSE, id = "id", time = "year", bootstrap = FALSE, 9 | reps = 2, degree = c(3, 2), verify = TRUE, ...) 10 | } 11 | \arguments{ 12 | \item{data}{A data.frame or tibble containing the variables of the model.} 13 | 14 | \item{formula}{An object of the class \code{\link[stats]{formula}}.} 15 | 16 | \item{gross}{If TRUE dependent variable is gross output.} 17 | 18 | \item{id}{A character with the name of the indicator variable.} 19 | 20 | \item{time}{A character with the name of the time variable.} 21 | 22 | \item{bootstrap}{An optional logical. If TRUE calculate bootstrap standard errors.} 23 | 24 | \item{reps}{The number of bootstrap replications.} 25 | 26 | \item{degree}{A vector with the number of the polynomial interactions in each stage of the routine.} 27 | 28 | \item{verify}{Verify if inputs are sorted.} 29 | 30 | \item{...}{Additional arguments.} 31 | } 32 | \description{ 33 | This function aims the estimation of Cobb-Douglas production functions using \href{https://doi.org/10.1016/j.econlet.2009.04.026}{Wooldridge (2009)} method. 34 | } 35 | \details{ 36 | Multipart formula must be specified in the following order: \code{y ~ free | capital | proxy | controls}. Additional controls are optional. 37 | It is possible to use more than one variable, although the use of more than one capital may not be theoretically identified. 38 | The function returns an object of the estprod or boot classes (if \code{bootstrap} is TRUE). 39 | } 40 | \examples{ 41 | data(estprod_data) 42 | wooldridge(data = estprod_data, var1 ~ var2 | var3 | var4, 43 | id = "id", time = "year", bootstrap = TRUE) 44 | } 45 | --------------------------------------------------------------------------------