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.
Suppressing the iterlog with mlogit for Stata 14Hello, I was looking to suppress the iterlog when running mlogit. I'm aware of set iterlog, but ran…
Invalid nameHello everyone, I would like to kindly ask the community for a help. I use STATA 16, Windows 10. Whe…
rdrobust questionI am interested in having my rdrobust regression have different bandwidths on each side. I put the f…
Question: how to compute a variable value based on its last value in a panel datasetDear All, I am trying to do the calculation illustrated in Excel with Stata. Specifically, I would …
Exporting table into LatexI am trying to produce the share of police stops per NYC borough in a table, then export it from Sta…
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