获取“is.data.frame(df)不是真的”错误“创建滞后...”行后,无法弄清楚原因。任何帮助,将不胜感激! ```{r,echo = TRUE}
df1 <- read.dta("~/Downloads/doesoil clean.dta")
df1 <- as.data.frame(df1)
str(df1)
```
```{r, echo=TRUE}
## Create lagged outcome variable for policy
df1 <- arrange(data, cty_name, year)
df1 <- group_by(data, cty_name) %>%
mutate(
oil_L1 = lag(oil, 1),
regime1_L1 = lag(regime1, 1) ,
islam_L1 = lag(islam, 1) ,
metal_L1 = lag(metal, 1) ,
log135_L1 = lag(log135, 1) ,
)
df1$log_oil_L1<-log(df1$oil_L1+.001)
df1<-dplyr::select(df1,
cty_name,
year,
regime1,# regime type , 1=Democracy
regime1_L1, ## Lagged regime type
oil_L1,## oil exports as percentage of GDP (lagged)
log_oil_L1,## Logged oil exports (lagged)
islam_L1,## percent islam (lagged)
metal_L1,## mineral exports as percentage of GDP (lagged)
mideast,## dummy if country is in the middle east
log135,## Logged per capita income
log135_L1) ## Logged per capita income (lagged)
df1$year<-as.numeric(df1$year)
```
尝试使用标注规范对数据进行子集化,教授将其作为起点提供,但我遇到了调试问题。
答案 0 :(得分:0)
您正在引用您与我们共享的代码中未定义的变量,&#34;数据&#34;。正如r2evans在评论中所提到的那样,使用您已分配给名称df1的data.frame可以解决您的问题。