0

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.

Julian
  • 6,586
  • 2
  • 9
  • 33
  • 1
    Not exactly sure what you want to achieve... have you noticed there is argument `shift` to `plm::lag` to switch between time-wise (default) and row-wise lagging? – Helix123 Jun 19 '23 at 17:00
  • Yes, I noticed. But I am using the time option – Pedro Camões Jun 19 '23 at 22:30
  • Maybe you want to show the code you use and the output it produces and the output you want to have, so we can better understand and help. – Helix123 Jun 20 '23 at 08:40

0 Answers0