Hi,
I have a bunch of IDs for which I need to replicate values for 208 weeks. The value for each week has to be the status of the ID holder which is either Derived, Transported, Listed, Not listed or Removed. So I need a value stating the status of each ID for each week. Doing it only by week is easy. However, I need the status for the IDs in the first week (week 0 ) by day. So my data should be looking in the raw form something like this.
However, when I run the code below, I get an error saying status1 already defined. Any ideas what I can do?
Also I need to reshape the code below from long to wide. So when I am dealing only with weeks its easy reshape wide status i(ID) j(week), But how do I do it if I need to reshape days and week as well? Any suggestions would be appreciated.
I have a bunch of IDs for which I need to replicate values for 208 weeks. The value for each week has to be the status of the ID holder which is either Derived, Transported, Listed, Not listed or Removed. So I need a value stating the status of each ID for each week. Doing it only by week is easy. However, I need the status for the IDs in the first week (week 0 ) by day. So my data should be looking in the raw form something like this.
ID | day 1 | day2 | day3 | day4 | day5 | day6 | day7 | week1 | week2 | week3 | week4 |
status | Listed | Listed | Listed | Listed | Listed | Listed | Derived | Derived | Derived | Derived | Derived |
Also I need to reshape the code below from long to wide. So when I am dealing only with weeks its easy reshape wide status i(ID) j(week), But how do I do it if I need to reshape days and week as well? Any suggestions would be appreciated.
Code:
forvalues a = 1/1 { keep if can_college == `a' forvalues w = 0/208 { if `w'==0 { forvalues d = 1/7{ qui gen status`d' = . qui replace status`d' = 1 if !inrange(faildate_1, edate_new,remdate_new) qui replace status`d' = 2 if inrange(faildate_1, edate_new, remdate_new) qui replace status`d' = 3 if (faildate_1 >= remdate_new) & !missing(remdate_new) qui replace status`d' = 4 if (tdate_2 <= faildate_1 ) & !missing(tdate_2) qui replace status`d' = 5 if (died <= faildate_1 ) & !missing(died) } } else { qui replace status`w' = . qui replace status`w' = 1 if !inrange(faildate_1+ `w'*7, edate_new,remdate_new) qui replace status`w' = 2 if inrange(faildate_1 + `w'*7, edate_new, remdate_new) qui replace status`w' = 3 if (faildate_1 + `w'*7 >= remdate_new) & !missing(remdate_new) qui replace status`w' = 4 if (tdate_2 <= faildate_1 + `w'*7) & !missing(tdate_2) qui replace status`w' = 5 if (died <= faildate_1 + `w'*7) & !missing(died) label define status`w' 1 "Not listed" 2 "Listed" 3 "Removed" 4 "Transported" 5 "Derived" label value status`w' status`w' } } } keep id status* reshape long status, i(id) j (week) save educ_plot_`a', replace } variable status1 already defined r(110)
Comment