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
Related Posts with merging the same dates into my data
Same value for duplicatesHello, statalist! I am struggling with the replace the value for the same person. In the dataset, t…
CIBAR (sort ascending)Wonder if possibel to apply sort ascending or sort descening funciton to cibar generated graph. for …
-putexcel- command not exporting results to excel fileI have written codes to export regression model results to excel file, and the codes are: Code: ve…
Impact of unmeasured confounders. episensi and average treatment effects mhboundsDear Experts, multiple sensetivity analysis are now available. First, I was going over episensi deve…
Adding together variablesHello, I apologize in advance for my lack of knowledge concerning STATA as I am not familiar with it…
Subscribe to:
Post Comments (Atom)
0 Response to merging the same dates into my data
Post a Comment