Hi,
I would appreciate your help with formatting date variables. I use Stata 15.
I would like to get YYYYMM-variables in a date formate and I used following syntax:
foreach var of varlist {
format `var' %12.0g
tostring `var', gen(junk`var')
gen junk`var'2 = mofd(date(junk`var', "YM"))
format junk`var'2 %tm
}
Then the result looks like this:
2010m1
2010m2
2010m3
2010m4
2010m5
2010m6
2010m7
2010m8
2010m9
201010
I wonder how I can get this result:
201001
201002
201003
201004
201005
201006
201007
201008
201009
201010
I have not found any help in the Stata manuals about working with dates and times.
Related Posts with Formatting date variable YYYYMM
combining histograms of different bin sizes and plotting gamma distribution on themHi all I have prepared histograms (attached) of % trip by trip lengths in the UK for two modes of t…
Creating categorical variables with multiple different conditions from continuous variablesHi, I am trying to create a categorical variable of "activity". I want 0=<150 mins of activity. …
predicted probability issueDear community! I am struggling with a choice of command to calculate predicted probabilities of eac…
Marginal effects of binary explanatory variable after craggitDear Statalist, Greetings! I was trying to estimate the drivers of farmers adoption decions. My dep…
Using and interpreting multi level mixed effects logictic regression with nested clusteringI have a dataset with around 30,000 participants, clustered into 20,000 families which are further c…
Subscribe to:
Post Comments (Atom)
0 Response to Formatting date variable YYYYMM
Post a Comment