Dear users,
I have a panel of life expectancy (e0) time series (yearly). I'm exploring alternative ways to categorize years affected by short-run deviations from trend with an eye to control for them in cross-country analyses. Setting filters and interpolations aside, I decided first of all to see what happens with the primitive criterion of excluding those years altogether. My problem concerns their identification. I define those "shock years" as the set of years of declining life expectancy plus years of recovery - the latter defined as the x consecutive years following the x consecutive years of decline. So, to exemplify, if a country time series displays 5 years of consecutive negative change in e0, I want to flag these years and the consecutive 5 years, as respectively "crisis" and "recovery".
I tried this:
Stata will not allow me to loop over the numlist of the time series operator because it understands L() as a function - one that indeed does not exist. I could avoid looping, given that the longest sequence of years of decline is not that long. However, I would like to understand my mistake properly and learn ways out - I'm new to time series operators and I might have missed something in the relevant TS guide entries.
Many thanks in advance
I have a panel of life expectancy (e0) time series (yearly). I'm exploring alternative ways to categorize years affected by short-run deviations from trend with an eye to control for them in cross-country analyses. Setting filters and interpolations aside, I decided first of all to see what happens with the primitive criterion of excluding those years altogether. My problem concerns their identification. I define those "shock years" as the set of years of declining life expectancy plus years of recovery - the latter defined as the x consecutive years following the x consecutive years of decline. So, to exemplify, if a country time series displays 5 years of consecutive negative change in e0, I want to flag these years and the consecutive 5 years, as respectively "crisis" and "recovery".
I tried this:
Code:
gen e0diff = f.e0-e0 gen crisis = 1 if e0diff<0 gen rcvy = 1 if !mi(e0diff) & e0diff>0 & l.crisis==1 forvalues n = 1/100 { replace rcvy = 1 if !mi(e0diff) & e0diff>0 & L(1/`n').rcvy==1 & ((2*`n')+1)L.crisis==1 }
Many thanks in advance
Comment