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: RE: re. strings and non-string: the month case
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: RE: re. strings and non-string: the month case
Date
Thu, 21 Nov 2013 16:33:29 +0000
Panos,
In addition to Nick's useful explanation of my suggestion, I should point out that the -encode- suggestion is probably better if you want a numeric variable with a label. My suggestion was aimed at a shortcut that gives you the numeric variable without the label. It is not as useful for creating the label (except possibly if you concatenate the number to the beginning of the string before encoding).
Following on with Nick's explanation, another possibility here (which I wouldn't necessary recommend, but which is interesting and instructive nonetheless) is:
. gen mydate=date(month,"M")
. format mydate %td_Month
Regards,
Joe
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Thursday, November 21, 2013 11:22 AM
To: [email protected]
Subject: Re: st: RE: re. strings and non-string: the month case
understanding what it does and doesn't do is important.
Joe is creating a daily date from monthly information alone and then extracting the month. That works because it is what is wanted, but the dates themselves are 1 Jan 1960, 1 Feb 1960, and so forth as without a day of the month Stata assumes 1 and without a year it assumes 1960.
You discard that day and year information in this case, but know how the trick was done.
Nick
[email protected]
On 21 November 2013 16:04, Joe Canner <[email protected]> wrote:
> Panos,
>
> In conjunction with -encode-, as suggested by Richard Goldstein, you might want to use the following statement to convert month names to month numbers:
>
> . gen month_num=month(date(MONTH,"M"))
PAPANIKOLAOU P.
> I have got a string variable: MONTH, where records the months of the year (e.g., January, February and so forth) on micro-data basis.
> Would you please assist me how best I would attach a set of label values where 1 refers to January, 2 is for February and so forth.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/