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.