Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: changing values of a string variable


From   Prakash Singh <prakashbhu@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: changing values of a string variable
Date   Tue, 24 Apr 2012 14:26:41 +0530

Thanks Nick for putting my words in a neat way.

I am not convince why use the command
replace firm1 = . if firm1 != "id_131":firm1
when you can use
replace firm1 = . if firm1 != 1 (suppose the value correnponding to
the value lebel id_131 is 1 which one can easly get to know)

Prakash

On Tue, Apr 24, 2012 at 1:47 PM, Ronnie Babigumira <rb.glists@gmail.com> wrote:
> Nick, this is neat, thanks.
>
> Tashi, this is certainly closer to what you had in mind
>
> encode firms, gen(firm1)
> replace firm1 = . if firm1 != "id_131":firm1
>
> Ronnie
>
> --
> 010100100110111101101110011011100110100101100101
>
>
>
>
> On Tuesday, April 24, 2012 at 9:52 AM, Nick Cox wrote:
>
>> Prakash's opening statement is incorrect. If you -encode- a string
>> variable, it loses no property and indeed stays exactly as it is. What
>> happens is that a numeric variable is created with value labels equal
>> to the string values.
>>
>> Tashi appears to be seeking something like the last line here
>>
>> sysuse auto
>> label def rep78 1 appalling 2 adequate 3 average 4 amazing 5 astounding
>> label val rep78
>>
>> . count if rep78=="average":rep78
>> 30
>>
>> For more, see in [U] and e.g.
>>
>> SJ-4-4 dm0009 . . . . . . . Stata tip 14: Using value labels in expressions
>> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K. Higbee
>> Q4/04 SJ 4(4):488--489 (no commands)
>> tips for using value labels in expressions
>>
>> Ken Higbee's paper is accessible at
>>
>> http://www.stata-journal.com/sjpdf.html?articlenum=dm0009
>>
>> This syntax has been in Stata a very long time. I don't use it, partly
>> because I keep forgetting about it and partly because I would need to
>> look it up to remember what it is, and my wild guess is that many
>> experienced users would say something similar.
>>
>> Nick
>>
>>
>> Prakash Singh [edited slightly]
>>
>> > when you -encode- any variable it loses its string property so
>> > there would be numeric value corresponding to id_131 in firms1 and you
>> > should use that value in your command line
>>
>>
>>
>> tashi lama
>>
>> > > I found matters similar to what I am going to post have been been discussed in the past but I am not sure if I understood. Here is my dataset
>> > >
>> > > hits firms
>> > > 3 id_6429
>> > > 10 id_131
>> > > 8 id_2837
>> > >
>> > > 12 id_90
>>
>> > > The problem is to have sth like this
>> > >
>> > > hits firms
>> > >
>> > > 3 .
>> > >
>> > > 10 id_131
>> > > 8 .
>> > >
>> > > 12 .
>> > >
>> > >
>> > > so I said 1. encode firm, gen(firm1)
>> > >
>> > > replace firm1=. if firm1!=id_131
>> > >
>> > > drop firms
>> > >
>> > > I also tried 2. replace firms="" if firms!="id_131"
>>
>> > > It didn't give me the expected output although I feel like my codes are correct at least in principle. Any idea?
>>
>> *
>> * 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/
>
>
>
> *
> *   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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index