Dear statalist members,

Im trying to manage my data. My data is like this dataset

clear all
input double id str6 V1 str6 V2 long V3 long V4 long V5
1 "A" "p" 34 20180103 20180430
1 "B" "p" 35 20160409 20160718
1 "B" "c" 34 20180203 20180530

end
gen mdate1 = mofd(daily(string(V4, "%8.0f"), "YMD"))
gen mdate2 = mofd(daily(string(V5, "%8.0f"), "YMD"))
gen length = mdate2 - mdate1 + 1
expand length
bys id mdate1 mdate2: gen mdate = mdate1[1] + _n-1

format mdate* %tm

list, sepby(id)


Because I don't want to have a repetitive date (see mdate variable), I want to reconfigure my data like this

clear all
input double id str6 mdate int A int B int D str6 A_V2 long A_V3 str6 B_V2 str6 B_V3
1 "2016m4" 0 1 0 "." 0 "p" 35
1 "2016m5" 0 1 0 "." 0 "p" 35
1 "2016m6" 0 1 0 "." 0 "p" 35
1 "2016m7" 0 1 0 "." 0 "p" 35
1 "2018m1" 1 0 0 "p" 34 "." .
1 "2018m2" 1 1 0 "p" 34 "c" 34
1 "2018m3" 1 1 1 "p" 34 "c" 34
1 "2018m4" 1 1 0 "p" 34 "c" 34
1 "2018m5" 0 1 0 "." 0 "c" 34
end


Thanks for your help