lag function returning contemporaneous values

31 views Asked by At

I am using the lag function (package plm) which is returning me the contemporaneous value, not the lagged one.

In this code regarding a panel of data (years, agencies), the chg variables is filed with zeros.

group_by(Cod) %>% 
mutate(orcam = orc*100/real,
chg = (orcam-lag(orcam))/lag(orcam)) %>%
ungroup()

I tried to create a function growth rate, this way

growth_rate <- function(x)(x/lag(x)-1)*100 
chg = growth_rate(orcam)

The problem persisted.

0

There are 0 answers