Dear All,
I got stuck on a seemingly very simple problem. More precisely, I want to calculate the average of a group's value and the respective value of the preceding group for that variable. Thereby, the value for each group ("threshold") is constant within the group ("country") but varies across groups.
I tried:
However, I want threshold_new to be the same within each country, i.e. I want _n-1 to refer to the previous group and not to the previous observation. There might be a solution with "rangestat", but as I was having trouble installing the package, I was wondering if there is a workaround similar to the code above?
Many thanks in advance.
I got stuck on a seemingly very simple problem. More precisely, I want to calculate the average of a group's value and the respective value of the preceding group for that variable. Thereby, the value for each group ("threshold") is constant within the group ("country") but varies across groups.
I tried:
Code:
bysort country: gen threshold_new = (threshold[_n-1]+threshold)/2
Many thanks in advance.
Comment