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.
Overlapping-rolling windowDear Statalisters, I am running into an issue with rolling windows and I need your kind help with t…
problem installing using the ssc commandI am using Stata/MC 16.1 on Windows 10 (also had the same problem using Ubuntu Linux 18.04). I have…
Cross-lagged panel models with binary and continuous outcome variables: gsem or sem (?) + other questionsGreetings, I'm running Stata 15.1 on OSX and working with yearly panel data. My hypothesis predicts…
What does 1.009e-12 mean?What does 1.009e-12 mean? Can you show it in a decimal expression? How to transfer it to decimal ex…
Concatenating multiple variables into one variableDear Statalist, I am struggling with the "egen - concat" command to join the list of 4 variables in…
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