Hi all,
I was trying to do something using a weights/forvalues to achieve the following:
I have ten countries (var: "country" and "countrycode") with 45 quarters (var: "quarter" ranging from 2010q1 to 2021q1) which I want to assign a variable <booming> if the variable rhp (real house prices) increases for 8 consecutive quarters.
bysort quarter countrycode: replace rise[n] = rise[_n+1] + 1 if rhp>rhp-1
The above is not allowed due to weights. But also does not take away the fact that it should also be set back to zero if there is a decline in a quarter.
So basically, what I want to achieve is for every country a variable that counts the number of consecutive quarters when rhp>L1.rhp and adds one to it if the condition is met and resets to zero if not.
It should kinda look like this: 1,2,3,4,5,6,7,8,9,10 (all rhp>L1.rhp), 0 (when L1.rhp>rhp), 1,2,3,4 and so forth.
That way I can simply assign a dummy equal to 0 or 1 in case >8 consecutive quarters of growth per country.
Do you have any advice?
Many thanks in advance!
Matthias
I was trying to do something using a weights/forvalues to achieve the following:
I have ten countries (var: "country" and "countrycode") with 45 quarters (var: "quarter" ranging from 2010q1 to 2021q1) which I want to assign a variable <booming> if the variable rhp (real house prices) increases for 8 consecutive quarters.
bysort quarter countrycode: replace rise[n] = rise[_n+1] + 1 if rhp>rhp-1
The above is not allowed due to weights. But also does not take away the fact that it should also be set back to zero if there is a decline in a quarter.
So basically, what I want to achieve is for every country a variable that counts the number of consecutive quarters when rhp>L1.rhp and adds one to it if the condition is met and resets to zero if not.
It should kinda look like this: 1,2,3,4,5,6,7,8,9,10 (all rhp>L1.rhp), 0 (when L1.rhp>rhp), 1,2,3,4 and so forth.
That way I can simply assign a dummy equal to 0 or 1 in case >8 consecutive quarters of growth per country.
Do you have any advice?
Many thanks in advance!
Matthias
Comment