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.
Could I include the survey data of "prefer not to say"?Dear friends, I collect survey data with categorical outcome variables whose outcome includes "prefe…
Merging Two Data SetHello Stata Users, I am trying to combine two different data sets according to the variables "Area" …
Difference in DifferenceHello, I'm trying to do a difference in difference for the data below. The treatment starts after Ja…
Interpreting outputs from "raschjmle" commandHi! I am doing my research on Rasch analysis for measuring knowledge. I am using Stata-14 to constru…
Counting number of variables across groupsHi, I have three variables KeyEventDates KeyEventHistory KeyEventDetails that I am splitting into s…
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