3
$\begingroup$

I am writing my Bachelor Thesis and I really need help with the TFP estimation. so far I have a dataset with log values of Value added (va), Labour (l), Capital (k), and Materials (m). The initial dataset is available here: https://drive.google.com/file/d/1aedWYABus1fQjKWxkOmYOmxv-qSja7hF/view?usp=sharing

So far my code is:

remove(list=ls())

library(plm)
library(dplyr)
library(ggplot2)
library(prodest)
library(estprod)
library(broom)

setwd("C:/Users/vadya/Desktop/baka")


Data <- read.csv("LV.csv", header=TRUE, sep=",")
str(Data)

summary(Data)

DataA <- Data %>% 
  filter(NACE == 'A') %>% 
  filter(VA > 0, L > 0, K > 0, M > 0) %>%
  mutate(l = log(L),
         va = log(VA),
         k = log(K),
         m = log(M))

wooldridge(data = DataA, va ~ l | k | m, id = "ID", time = "Year", bootstrap = TRUE, gross = FALSE)


levinsohn_petrin(data = DataA, va ~ l | k | m, id = "ID", time = "Year", bootstrap = TRUE, gross = FALSE)


olley_pakes(data = DataA, va ~ l | k | m, id = "ID", time = "Year", bootstrap = TRUE, gross = FALSE)

mod1 = estprod::levinsohn_petrin(data = DataA,
                                 formula = va ~ l | k | m, 
                                 id = "ID", 
                                 time = "Year", 
                                 reps = 20,
                                 gross = FALSE) 
mod1
  
mod2 = prodest::prodestLP(DataA$va,
                      fX = DataA$l,
                          sX = DataA$k, 
                      pX = DataA$m,
                          idvar = DataA$ID,
                      timevar = DataA$Year,
                          opt='optim',
                          exit = FALSE,
                          tol = 1e-100)  

omega = prodest::omega(mod2) 

So far, the problem is the following - with estprod package I get only coefficients estimated for l and k, without m estprod result

With prodest package, the problem is the following: prodest result

A saw the same discussion in another theme on StackExchange where a guy was asking the same question, but he had provided some part of his data, and everything worked. But in my case the problems are different.

Does anyone faced the same problem, and is it possible to solve these issues, since I only have begun studying TFP in R, so I would really appreciate your help and any impact provided. Thanks in advance!!!

$\endgroup$
2
  • $\begingroup$ Not an answer, but somewhere in your code, you are trying to join two data frames of different sizes. You find that, you find the problem $\endgroup$
    – Jamzy
    Commented Oct 2, 2020 at 0:29
  • $\begingroup$ Yes, I do understand that the error in prodest package says that, but the dataset is the size that it is, so I basically use the same dataset (with the same variables) as the author of prodest function did $\endgroup$ Commented Oct 2, 2020 at 8:45

1 Answer 1

1
$\begingroup$

You get the error because your ID is string and the prodestLP function has a problem with that here - leading to incorrectly specifying that replacement matrix in this case.

You can solve this issue with:

 DataA$ID<-as.numeric(as.factor( DataA$ID))

once you declare the ID as numeric the code works:

     mod2 = prodest::prodestLP(DataA$va,
+                            fX = DataA$l,
+                            sX = DataA$k, 
+                            pX = DataA$m,
+                            idvar = DataA$ID,
+                            timevar = DataA$Year,
+                            opt='optim',
+                            exit = FALSE,
+                            tol = 1e-100)  
>  
>  omega = prodest::omega(mod2) 

with output:

    summary(mod2)

-------------------------------------------------------------
-               Production Function Estimation              -
-------------------------------------------------------------
                   Method :    LP              
-------------------------------------------------------------
                               fX1       sX1 
Estimated Parameters      :   0.107     0.458 
                             (0.012)   (0.052)
-------------------------------------------------------------
N                         :  4397
-------------------------------------------------------------
Bootstrap repetitions     :  20
1st Stage Parameters      :  0.107     0.249 
Optimizer                 :  optim
-------------------------------------------------------------
Elapsed Time              :  0.02 mins

-------------------------------------------------------------


summary(omega)
       V1        
 Min.   :-3.452  
 1st Qu.: 1.428  
 Median : 1.842  
 Mean   : 1.778  
 3rd Qu.: 2.202  
 Max.   : 4.492  

Update these are the packages I am running and code before the one shown above (also I am running R version 4.0.2 (2020-06-22)):

rm(list = ls())

Data <- read.csv("~/R studio/excercises in randomness/tfp2/Gmail/LV.csv")

 View(Data)
 
 
 

 pckg<-c("plm","readxl","dplyr","ggplot2", "broom","prodest", "estprod")
 #install.packages(c("plm","readxl","dplyr","ggplot2", "broom","prodest", "estprod"))
 lapply(pckg, require, character.only = TRUE)
 
 head(Data)
 
 summary(Data)
 
 DataA <- Data %>% 
         filter(NACE == 'A') %>% 
         filter(VA > 0, L > 0, K > 0, M > 0) %>%
         mutate(l = log(L),
                va = log(VA),
                k = log(K),
                m = log(M))
$\endgroup$
11
  • $\begingroup$ 1muflon1, thank you a lot for clarification, however, may I ask two more questions - 1. is it somehow possible to display not only floating and state variable but also the intermediate inputs? 2. Do you know how to interpret these t-statistics in brackets - I mean is it possible to display the p-value as well as like in other regressions formula with ***, **, *? $\endgroup$ Commented Oct 2, 2020 at 17:44
  • $\begingroup$ @WadimiLchuk you are welcome, if you think my answer answered the Q consider accepting it. Regarding those further questions 1. you can recover all betas of the model using print(mod2@Model[["FSbetas"]]) but only intercept fX1 and sX1 are labeled. 2. Those values in parentheses are not t-statistics but bootstrapped standard errors you can calculate t-statistics by dividing coefficients by standard errors ($\beta/SE$). The critical values for t-statistics with large number of observations are approximately 1.65, 1.96 and 2.58 for two sided test for 90,95 and 99 confidence respectively. $\endgroup$
    – 1muflon1
    Commented Oct 2, 2020 at 18:31
  • $\begingroup$ You can use the built in qt function in R to get precise critical values. There is also build in function for p-value based on t-statistics (the pt built in function) $\endgroup$
    – 1muflon1
    Commented Oct 2, 2020 at 18:44
  • 1
    $\begingroup$ I am so grateful to you, that you helped me to solve my issue. Are also are you a specialist in estprod package with simplier formula? I mean, why there are also only 2 coeffs printed, because as far as I researched to retrieve omega(TFP) from this formula you have to manually code it, but the issue there is the third coefficient that is before Materials variable is not printed out? $\endgroup$ Commented Oct 2, 2020 at 20:31
  • 1
    $\begingroup$ Yes, sure, I have already written to the author. But again I want to thank you for your help as well as explanations. $\endgroup$ Commented Oct 3, 2020 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.