1

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.

Helix123
  • 3,502
  • 2
  • 16
  • 36
kezeng
  • 11
  • 1
  • Here a similar problem with the dummies package with RMD was reported: https://stackoverflow.com/questions/47976971/r-dummies-package-weird-column-names-when-knitted-via-rmd – J_F Apr 26 '19 at 20:20
  • Thanks J_F, i tried this one but failed. still object not found – kezeng Apr 29 '19 at 14:37
  • The variable `cigar_data63` is not part of the data set `Cigar` as included in the `plm` package. Likely, you created `cigar_data63` yourself but did not include the code to produce it, at least it is not included in your post (non-reproducible example). – Helix123 Aug 09 '21 at 18:29

0 Answers0