I had a problem when using the pgmm
code in plm
package. It seems it works well in chunks but when I was knitting it into PDF, it shows me the error message
$Error in eval(predvars, data, env).
can not find the object "cigar_data63"
calls: <anonymous> ... model.frame.Formula ->
model.frame -> model.frame.default -> eval -> eval$
The data i am using is the built in dataset in the plm package. which is the cigar data.
---
title:
short:
journal: "AER" # AER, AEJ, PP, JEL
month: "`r format(Sys.Date(), '%m')`"
year: "`r format(Sys.Date(), '%Y')`"
author:
output: rticles::aea_article
---
library(plm)
data(Cigar)
cigar_data = log(Cigar)
cigar_data$state = Cigar$state
cigar_data$year = Cigar$year
cigar_data$lsales = lag(cigar_data$sales,1)
library(dummies)
cigar_data = cbind(cigar_data,dummy(cigar_data$year))
cigar_data = pdata.frame(cigar_data,index = c("state","year"))
q3_ols = plm(sales ~ lag(sales,1) + price + ndi + pimin,
data = cigar_data, effect = "time", model = "within")
q3_gmm = pgmm(sales ~ lag(sales,1) + price + ndi + pimin|
price + ndi + pimin + cigar_data63,
data = cigar_data, effect = "individual",
model = "twosteps")
summary(q3_ols)
summary(q3_gmm)
The result should produce the (panel) GMM estimator.