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
"PAPANIKOLAOU P." <[email protected]>
To
<[email protected]>
Subject
RE: st: RE: re. strings and non-string: the month case
Date
Thu, 21 Nov 2013 17:23:51 -0000
Dear All,
Thank you so much.
I have followed your suggestions through: 1. Use the encode with the
generate option, creating a numerical variable. Use label define and
label values, see below. Following this, I run the tab command to get
the frequencies, which are presented in the correct order (jan-Dec).
But, when I do label list, I do not understand why the list is in
different order (1 April, 2 August and so forth) and with the full names
of the month. I would have expected to see that the label list would
present the months in the jan-dec order. I am confused why this has
happened. Would you please let me know. Many thanks, Panos
enc Month, gen(MONTHS_NUM)
label define label_mon 1 "Jan" 2 "Feb" 3 "Mar" 4 "Apr" 5 "May" 6 "Jun"
7 "Jul" 8 "Aug" 9 "Sep" 10 "Oct" 11 "Nov" 12 "Dec"
. label values MONTHS_NUM label_mon
. tab MONTHS_NUM
Month | Freq. Percent Cum.
------------+-----------------------------------
Jan | 393 8.92 8.92
Feb | 330 7.49 16.41
Mar | 340 7.72 24.13
Apr | 348 7.90 32.03
May | 379 8.60 40.64
Jun | 376 8.54 49.17
Jul | 368 8.35 57.53
Aug | 418 9.49 67.01
Sep | 423 9.60 76.62
Oct | 328 7.45 84.06
Nov | 347 7.88 91.94
Dec | 355 8.06 100.00
------------+-----------------------------------
Total | 4,405 100.00
. label list MONTHS_NUM
MONTHS_NUM:
1 April
2 August
3 December
4 February
5 January
6 July
7 June
8 March
9 May
10 November
11 October
12 September
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 21 November 2013 16:45
To: [email protected]
Subject: Re: st: RE: re. strings and non-string: the month case
want but what lies underneath will be daily dates, specifically 0, 31,
60, ... That could cause more confusion than it solves.
Nick
[email protected]
On 21 November 2013 16:33, Joe Canner <[email protected]> wrote:
> 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/
*
* 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/