I am trying to combine the fitted value of the dependent variable of log-log model. My data set is a unbalanced panel. I tried to do it in the way as indicated here. But my question is different because I have already converted my big data set into a plm object and it's a log dependent variable.
My simple data set can be accessed via the following codes.
dat = structure(list(Time = structure(c(9L, 7L, 15L, 1L, 17L, 13L,
11L, 3L, 23L, 21L, 19L, 5L, 10L, 8L, 16L, 2L, 18L, 14L, 12L,
4L, 24L, 22L, 20L, 6L), .Label = c("Apr-00", "Apr-01", "Aug-00",
"Aug-01", "Dec-00", "Dec-01", "Feb-00", "Feb-01", "Jan-00", "Jan-01",
"Jul-00", "Jul-01", "Jun-00", "Jun-01", "Mar-00", "Mar-01", "May-00",
"May-01", "Nov-00", "Nov-01", "Oct-00", "Oct-01", "Sep-00", "Sep-01"
), class = "factor"), Firm = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), Out = c(161521L,
142452L, 365697L, 355789L, 376843L, 258762L, 255447L, 188545L,
213663L, 273209L, 317468L, 238668L, 241286L, 135288L, 363609L,
318472L, 446279L, 390230L, 118945L, 174887L, 183770L, 197832L,
317468L, 238668L), Lab = c(261L, 334L, 156L, 134L, 159L, 119L,
41L, 247L, 251L, 62L, 525L, 217L, 298L, 109L, 7L, NA, 0L, 50L,
143L, 85L, 80L, 214L, 525L, 217L), Cap = c(13L, 15L, 14L, 12L,
15L, 12L, 45L, 75L, NA, 12L, 15L, 16L, 42L, 45L, 24L, 56L, 12L,
12L, 45L, NA, 15L, 12L, 15L, 16L)), .Names = c("Time", "Firm",
"Out", "Lab", "Cap"), class = "data.frame", row.names = c(NA,
-24L))
My data set looks like below and with missing data of the predictors.
+--------+------+--------+-----+-----+ | Time | Firm | Out | Lab | Cap | +--------+------+--------+-----+-----+ | Jan-00 | A | 161521 | 261 | 13 | | Feb-00 | A | 142452 | 334 | 15 | | Mar-00 | A | 365697 | 156 | 14 | | Apr-00 | A | 355789 | 134 | 12 | | May-00 | A | 376843 | 159 | 15 | | Jun-00 | A | 258762 | 119 | 12 | | Jul-00 | A | 255447 | 41 | 45 | | Aug-00 | A | 188545 | 247 | 75 | | Sep-00 | A | 213663 | 251 | | | Oct-00 | A | 273209 | 62 | 12 | | Nov-00 | A | 317468 | 525 | 15 | | Dec-00 | A | 238668 | 217 | 16 | | Jan-01 | B | 241286 | 298 | 42 | | Feb-01 | B | 135288 | 109 | 45 | | Mar-01 | B | 363609 | 7 | 24 | | Apr-01 | B | 318472 | | 56 | | May-01 | B | 446279 | 0 | 12 | | Jun-01 | B | 390230 | 50 | 12 | | Jul-01 | B | 118945 | 143 | 45 | | Aug-01 | B | 174887 | 85 | | | Sep-01 | B | 183770 | 80 | 15 | | Oct-01 | B | 197832 | 214 | 12 | | Nov-01 | B | 317468 | 525 | 15 | | Dec-01 | B | 238668 | 217 | 16 | +--------+------+--------+-----+-----+
I can get the fitted values using the following codes
library(zoo)
library(plm)
Sys.setlocale("LC_TIME", "English")
dat["time1"] <- as.yearmon(dat$Time,format="%b-%y")
pdat <-pdata.frame(dat,index=c("Firm","time1"))
Model1<- plm(log(Out) ~ lag(log(Cap), 1) + log(Lab + 1),
model = "within", data=pdat)
summary(Model1)
library(data.table)
FV_Log <- data.table(Model1$model[[1]] - Model1$residuals)
But the observations of the pdat is 24 observations FV_Log is 19 observations, so I am unable to merge it to pdat. My pdat is large with several thousands of observations and I have created many variables using codes. So any help to merge the fitted value into the original pdat with properly (without changing the order) would be much appreciated.