I compute the following code:
df <- df %>%
mutate(PPE = (prop)+(equip))
# create new variable depending on this
df <- df %>%
mutate(dependent = (PPE - lag(PPE))/lag(assets))
and when I look at the data, PPE returns NA because equip has a NA value. However, say prop = 1 and equip = NA, I would like PPE to return 1 (and not NA). How can I change this? There is an example below of what I would want (where the first observation has to return NA for the dependent variable as I am using lag):
prop equip assets PPE dependent
1 NA 2 1 NA
1 NA 1 1 0.5
NA 4 2 4 3
3 3 1 6 1
8 NA 2 8 2
Thanks in advance for any help on this!