Change the date format

I have a date variable with the format "yyyymmdd" - say, 19501230. Now how can I convert this into the format "yyyymm" or any other format that I want? I'm using Stata 9 at the moment.

Thanks for your help!


New Member
I am sure there is another simple way of doing this, but I usually convert the date to a string so I can extract what I want. So the syntax would be:
1. tostring var, replace
2. gen year=substr(var1, 1, 4)
3. gen month=substr(var1, 5, 2)
If you would like to put it together,
4. gen _newdate=year + month.

Hope it helps.
try looking into "date()" command - in general type "help date" and you will get a lot of information on how stata handels data. When it comes to date(), try
"date(string_var_name, yyymmdd)"