New to this forum, so sorry for the wordy title.
I have 9 waves of individual level panel data on disability. Each observation includes a 9-digit string variable made up of 1's and 2's called 'trajectory' which records an individual's disability trajectory. For example, 111222111 would mean that they were not disabled in waves 1,2,3, they were disabled in waves 4,5,6 and not disabled in waves 7,8,9.
I wish to generate a new variable called 'chronicity' which records the length of disability. This variable would be equal to 0 if the individual is never disabled, 1 if they are disabled in a single period, 2 if they are disabled in 2 consecutive periods, 3 if they are disabled in 3 consecutive periods and so on.
The beginning of the code, where I denote the 'never-disabled' individuals is simple enough:
gen chronicity = .
replace chronicity = 0 if trajectory=="111111111"
However, when I wish to assign a 1 to denote the single-period disabled, I am struggling with the code. Here is an example of doing it wrong so that hopefully you can get the idea:
replace chronicity = 1 if trajectory=="111111112" | trajectory=="111111121" | trajectory=="111111211" | trajectory=="111112111" | trajectory=="111121111" | trajectory=="111211111" | "112111111" | trajectory=="121111111" | trajectory=="211111111"
Error: type mismatch
I've tried to use the inlist command too but this has been unsuccessful.
I'd be grateful for any help or ideas.
John
Related Posts with Generate new variable in panel data on the condition that another variable is contained within a list.
Delete observations under conditionsHi, I have a question that I hope someone can answer. I'm still pretty new to stata, so excuse me if…
Marginal effects-interpretationDear all, I am using a logit model to find which are the possibities the dependent variable Y to be…
Paneldata Fixed Effects with and without robust leads to the same resultHello, I hope anyone can help me. I have a unbalanced Panel. Hausmann leads me to use for further an…
hetprobit and robustHello, I have been readig on this forum and if I understand correctly, hetprobit estimates a probit…
Showing 95%-CI intervals in bar graphHello everyone In my data I have a dichotomous variable (=value) for three different conditions (wh…
Subscribe to:
Post Comments (Atom)
0 Response to Generate new variable in panel data on the condition that another variable is contained within a list.
Post a Comment