How to right two lags periods?

I have a question about R; i would like to use two lags periods instead of one (please check my below code) in my model but i don't know how to whrite it in R. Can someone help please?

Here below details of my R code:

library(plm)
fixed = plm(sp ~lag(debt)+lag(I(debt^2))+outgp+gvex+vlimp+vlexp+bcour+infcpi, data=pdata, index=c("country", "year"), model="within")

lag has a k parameter
Type ?lag in your console to read about it

@nirgrahamuk thanks, so i can whrite something like k = 1:2.

sorry, I was wrong about the param name. it is in fact n
it cant be called simultaneously with two n values.
call the function as many times as you want to give a different n.

okay @nirgrahamuk , can you please give me an example?

library(plm)


data("Grunfeld", package = "plm")
ols <- plm(inv ~ value + capital, Grunfeld, model = "pooling")
ols2 <- plm(inv ~ value + lag(capital), Grunfeld, model = "pooling")
ols3 <- plm(inv ~ value + capital + lag(capital), Grunfeld, model = "pooling")
ols4 <- plm(inv ~ value + capital + lag(capital) + lag(capital,k = 2), Grunfeld, model = "pooling")
1 Like

@nirgrahamuk thanks a lot for the details,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.