<p>I have a question regarding the usage of unbalanced panel data for TFP estimation by using the <em>prodest</em> package.</p>
<p>The dataset could be found here: <a href="https://drive.google.com/file/d/1W5pva05hRiruo1AMNc62ln0GNtcVr5p6/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1W5pva05hRiruo1AMNc62ln0GNtcVr5p6/view?usp=sharing</a></p>
<p>As you can see from the dataset, there are a lot of firms that have not reported some values in specific years, ending up with unbalanced panel data.</p>
<p>The code is the following. BUT in case I do not filter the data with &gt;0 values, I receive error messages coming from the estimation of TFP, saying that there are NaNs.</p>
<pre><code>remove(list=ls())

library(plm)
library(dplyr)
library(ggplot2)
library(prodest)


pckg&lt;-c(&quot;plm&quot;,&quot;readxl&quot;,&quot;dplyr&quot;,&quot;ggplot2&quot;,&quot;prodest&quot;)
#install.packages(c(&quot;plm&quot;,&quot;readxl&quot;,&quot;dplyr&quot;,&quot;ggplot2&quot;,&quot;prodest&quot;))
lapply(pckg, require, character.only = TRUE)

# Set the working directory
setwd(&quot;C:/Users/vadya/Desktop/LT original currency&quot;)

# Downloading the survey data
Data &lt;- read.csv(&quot;LToc.csv&quot;, header=TRUE, sep=&quot;,&quot;)
str(Data)

Data<span class="math-container">$ID&lt;-as.numeric(as.factor(Data$</span>ID))

summary(Data)

# Creating a panel data frame

DataA &lt;- Data %&gt;% 
  #filter(NACE == 'A') %&gt;% 
  #filter(TURN &gt; 0, TFA &gt; 0, FA &gt; 0, VA &gt; 0, L &gt; 0, M &gt; 0) %&gt;%
  mutate(ID = ID,
         Year = Year,
         turn = log(TURN),
         tfa = log(TFA),
         fa = log(FA),
         va = log(VA),
         cogs = log(COGS))
         #l = log(L),
         #m = log(M))
################################################################################################

mod2ACF &lt;-  prodest::prodestACF(DataA<span class="math-container">$va, fX = DataA$</span>cogs, sX = DataA<span class="math-container">$tfa, pX = DataA$</span>cogs, idvar = DataA<span class="math-container">$ID, timevar = DataA$</span>Year, 
                                R = 100, cX = NULL, opt = 'optim', theta0 = NULL, cluster = NULL)  

mod2ACF
omegaACF &lt;- prodest::omega(mod2ACF)
summary(mod2ACF)
summary(omegaACF)


mod2W &lt;-  prodest::prodestWRDG(DataA<span class="math-container">$turn, fX = DataA$</span>cogs, sX = DataA<span class="math-container">$tfa, pX = DataA$</span>cogs, idvar = DataA<span class="math-container">$ID, timevar = DataA$</span>Year, 
                               cX = NULL)  
mod2W
omegaW &lt;- prodest::omega(mod2W)
summary(mod2W)
summary(omegaW)

####################################################################################################################################
</code></pre>
<p>If I do not filter the dataframe, in the TFP estimation part (e.g., ACF method) I get the following error message.</p>
<p><a href="https://i.sstatic.net/nVli1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nVli1.png" alt="enter image description here" /></a></p>
<p>Am I doing something wrong, and is there a way to make the <em>prodest</em> functions to work with unbalanced panel data?</p>
<p>Thanks in advance for the ideas! Would really much appreciate your concern!</p>

CC BY-SA 4.0
2020-12-23T13:15:54.733Z
Did you just take the logarithm of a negative number?
Jesper Hybel
CC BY-SA 4.0
2020-12-23T13:38:09.880Z
Yes and no, because if you filter > 0, despite the negative values, you also delete the n.a. values, which I do not want to filter out
Wadim iLchuk
<econometrics><production-function><productivity><r><firm>
Unbalanced panel data in prodest package in R
Wadim iLchuk
# Unbalanced panel data in prodest package in R

(Asked by: username_0 on 2020-12-23)

I have a question regarding the usage of unbalanced panel data for TFP estimation by using the prodest package.
The dataset could be found here: https://drive.google.com/file/d/1W5pva05hRiruo1AMNc62ln0GNtcVr5p6/view?usp=sharing
As you can see from the dataset, there are a lot of firms that have not reported some values in specific years, ending up with unbalanced panel data.
The code is the following. BUT in case I do not filter the data with >0 values, I receive error messages coming from the estimation of TFP, saying that there are NaNs.
remove(list=ls())

library(plm)
library(dplyr)
library(ggplot2)
library(prodest)


pckg<-c("plm","readxl","dplyr","ggplot2","prodest")
#install.packages(c("plm","readxl","dplyr","ggplot2","prodest"))
lapply(pckg, require, character.only = TRUE)

# Set the working directory
setwd("C:/Users/vadya/Desktop/LT original currency")

# Downloading the survey data
Data <- read.csv("LToc.csv", header=TRUE, sep=",")
str(Data)

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

summary(Data)

# Creating a panel data frame

DataA <- Data %>% 
  #filter(NACE == 'A') %>% 
  #filter(TURN > 0, TFA > 0, FA > 0, VA > 0, L > 0, M > 0) %>%
  mutate(ID = ID,
         Year = Year,
         turn = log(TURN),
         tfa = log(TFA),
         fa = log(FA),
         va = log(VA),
         cogs = log(COGS))
         #l = log(L),
         #m = log(M))
################################################################################################

mod2ACF <-  prodest::prodestACF(DataA$va, fX = DataA$cogs, sX = DataA$tfa, pX = DataA$cogs, idvar = DataA$ID, timevar = DataA$Year, 
                                R = 100, cX = NULL, opt = 'optim', theta0 = NULL, cluster = NULL)  

mod2ACF
omegaACF <- prodest::omega(mod2ACF)
summary(mod2ACF)
summary(omegaACF)


mod2W <-  prodest::prodestWRDG(DataA$turn, fX = DataA$cogs, sX = DataA$tfa, pX = DataA$cogs, idvar = DataA$ID, timevar = DataA$Year, 
                               cX = NULL)  
mod2W
omegaW <- prodest::omega(mod2W)
summary(mod2W)
summary(omegaW)

####################################################################################################################################

If I do not filter the dataframe, in the TFP estimation part (e.g., ACF method) I get the following error message.

Am I doing something wrong, and is there a way to make the prodest functions to work with unbalanced panel data?
Thanks in advance for the ideas! Would really much appreciate your concern!

**Tags:** econometrics, production-function, productivity, r, firm

> **Comments:**
> **username_1**: Did you just take the logarithm of a negative number?  
> **username_0**: Yes and no, because if you filter > 0, despite the negative values, you also delete the n.a. values, which I do not want to filter out  

---

## 0 answers

