Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem using date() and format


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Problem using date() and format
Date   Wed, 5 Sep 2012 17:41:43 +0200

On Wed, Sep 5, 2012 at 5:23 PM, Jen Zhen wrote:
> I have a string variable with values 199301, 199302, 199303, ...,
> 199312, 199401, and so on.
> I would like to convert it to a Stata date variable and then format it
> so that when I browse the dataset values will be displayed as 1993m1,
> 1993m2, etc.
>
> I tried (amongst others):
>
> gen date=date(string,YM)
> format date %tm
>
> and at least one of those 2 lines of code must have been wrong, as I
> get shown values like 2972m1

*----------- begin example ----------
clear all
input str6 strdate
"199301"
"199302"
end

gen date=date(strdate,"YM")
replace date = mofd(date)
format date %tm
*------------- end example ----------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index