I have a panel dataset which is similar to the one below:
Country Ccode Year Happiness Power ID
1 France FR 2000 1000 1000 01
2 France FR 2001 1200 1400 01
3 France FR 2000 1400 1800 02
4 France FR 2001 1600 2200 02
5 UK UK 2000 1000 1000 03
6 UK UK 2001 1000 1000 03
7 UK UK 2000 1000 1000 04
8 UK UK 2001 1000 1000 04
What I am actually interested in is to what degree a variable is elastic with respect to time. In calculating this elasticity I want to make use of the panel data.
This is how far I got:
library(tidyverse)
df <- df %>%
arrange(ID, Year)
group_by(ID) %>%
mutate_if(is.numeric, funs(d = . - lag(.)))
But this just calculates the differences for each variable instead of the variance of a specific one.
Any suggestions on how to do this properly?
If I understand correctly, you want to calculate the variance of the numeric variables per year?