I would like to create from some start and end dates dummy variables which take value 1 if in the range. For example, from
id start end
1 01072014 05072014
1 05012014 06012015
I would like to get
id start end d_01012014 d_02012014 d_03012014 ... d_01052014 ... d_31122014
1 01012014 02012014 1 1 0 0 0
1 01052014 02052015 0 0 0 1 0
So that I eventually can reshape long my data, dropping all observations out of dayrange. My idea was to use a loop with stata date format, somethin like this:
foreach i in *stataformat startdate*/*stataformat enddate* {
generate d_`i'=1 if `i'>=start & `i'<=end
}
But the problem from this method is that my variables would alle have incomprensible names. So do you either suggest another approach, or have an idea how to rename variables containing stata datecodes to 'understandable' names? Thanks a lot!