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
legend positionDear All, I have this data set Code: * Example generated by -dataex-. To install: ssc install datae…
Industry fixed effects with the inrange commandHi there, I am currently trying to replicate an empirical study that uses a regression model with t…
Appending text filesHi all, I have ten txt files that I would like to append into one stata spreadsheet. Any suggestion…
Results from a loop with quarterly and weekly data are different in relation to the sort of data: What is happening here?Hi I have a dataset that includes a quarterly_macro variable which is the same for each week of the…
xtpmg, mg or dfe maximum number of iterations exceeded error messageDear statalist users, I am running xtpmg on stata 16.0. When I use the xtmpg, pmg option, my regres…
Subscribe to:
Post Comments (Atom)
0 Response to merging the same dates into my data
Post a Comment