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
Generate new variable based on existing dataI am using Stata 16.1 and would like to generate a new variable based on the ADM1 (region) name and …
Restricting Loop to Observation NumberI wish to create a variable that looks something like 1994M1, 1994M2.....1994M12 to indicate the mon…
Summing across variables with conditionsHello, I am working with a data set where the variables represent questions from a survey that used…
🗎 Temporary file with -tempfile-Dear All, I am looking for a way to make use of temporary files with the putpdf image command. Unfo…
how stata applys to treat tobit model- payment card approachHi college, I am learning econometrics on my own (as it is not my major in university), but hope to …
Subscribe to:
Post Comments (Atom)
0 Response to merging the same dates into my data
Post a Comment