The variable gdp_pc_ppp
corresponds to y in the equation. The variable gdp_pc_ppp
is already sorted from the smallest to largest value. The variable world_pop_share
corresponds to p in the equation.
I need to write code in R that creates a new variable as follows:
For the first row, it evaluates to NA
For the second row: (651.9531 - 378.5343)*9.568926e-03*2.636202e-03
For the third row: ((742.9709 - 651.9531)*8.084378e-03*9.568926e-03)
+ ((742.9709 - 378.5343)*8.084378e-03*2.636202e-03)
For the fourth row: ((744.1971 - 742.9709)*1.878016e-03*8.084378e-03)
+ ((744.1971 - 651.9531)*1.878016e-03*9.568926e-03)
+ ((744.1971 - 378.5343)*1.878016e-03*2.636202e-03)
So on and so forth for the following observations.
I need to do this for different years, therefore, I was trying to do it within the tidy verse syntax.
For example:
d = d %>%
group_by(year) %>%
mutate( INSERT HERE FUNCTION THAT WOULD CALCULATE EQUATION ABOVE )
Thank you.