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
How to handle missing data?Hi all, I am investigating health disparities in some Sub-Saharan Africa countries. Ethnicity is one…
Predictive Modeling using StataAny in depth books or tutorials on modeling with Stata that might be recommended? …
Stata commmands to analyze data where each record contains monthly totals: aggregate data problem but not really a wide to long solutionHi, I have some health centre data from Africa where each record consists of fields that represent …
Interaction with treatment in cubic spine plotDear Statalist, I want to plot the hazard ratio for survival over age using a restricted cubic spli…
dstdize and standardisation by genderI followed the guidance on sex standardisation from here https://www.stata.com/manuals13/rdstdize.pd…
Subscribe to:
Post Comments (Atom)
0 Response to merging the same dates into my data
Post a Comment