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
Reshaping data from wide to long, creating new j variableHi, UGENT HELP PLEASE I need to reshape my data from wide too long in order to merge it with alrea…
Merging observations into one variableI am working with survey data. Respondents are given the option to respond in different units for so…
Graph bar - Centering one graph when using -by()-Hi everyone, I'm making a graph for a variable with three categories that resembles the following: …
Graph bar -Hi everyone, I'm making a graph for a variable with three categories that resembles the following: …
ROC commands with multiple variablesHello, I would like to calculate the AUC using one of the roc commands. My reference/outcome variab…
Subscribe to:
Post Comments (Atom)
0 Response to Formatting date variable YYYYMM
Post a Comment