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: Destringing variable


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Destringing variable
Date   Sat, 12 May 2012 19:57:49 +0100

I infer from this that Aminu has a string variable -month- with values
like "JANUARY" and wants a corresponding numeric variable with values
like 1. If so, then -destring- has no role in this conversion. Aminu
needs to define a set of labels, e.g.

label def MONTH 1 "JANUARY" ... 12 "DECEMBER"

(clearly you need to complete the set where I have typed ...)

and then use -encode-:

encode month, gen(nmonth) label(MONTH)

Nick

On Sat, May 12, 2012 at 6:10 PM, Richard Goldstein
<[email protected]> wrote:

> there are a number of typos in your command; first, you have generated
> month2 and set it to 0 for everyone; it therefor can not possibly equal
> "january" regardless of case
>
> second, after changing the variable being referred to in your "if"
> statement (e.g., to month), note that strings must be (a) in
> doublequotes and (b) in the same case in your command as they are in the
> data
>
> why not use the -destring- command?

On 5/12/12 1:04 PM, Shittu, Aminu wrote:

>> I am trying to destring the var name -month- using the following command but
> the response was "january not found." Was it due to error in writing the
> command
> or because all months (JANUARY to DECEMBER) were entered in UPPERCASE
> letter?
>>
>>
>> gen month2=0
>> replace month2=1 if (month2==january)
>> -january not found-
>>
*
*   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