Running lagged regressions with lapply and two arguments

前端 未结 2 1953
渐次进展
渐次进展 2021-01-25 00:12

I am running multiple univariate regressions, like in this reproducible example:

require(dynlm)
data(USeconomic)
US<-USeconomic
vars<-colnames(US)[-2]
a<         


        
2条回答
  •  死守一世寂寞
    2021-01-25 00:26

    To construct R formula, you must paste it all together, not just the predictor side of it. So you need something like:

    formula <- as.formula(
        paste("log(GNP)~",
            paste("L(",rep(vars,each=3),",",l,")",sep=""),
            sep = ""
        )
    )
    

    and then run

    dynlm(formula, data = ...)
    

提交回复
热议问题