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   Ronnie Babigumira <rb.glists@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: changing values of a string variable
Date   Tue, 24 Apr 2012 09:05:50 +0200

Some suggestions. If all you want is a new variable that takes on the value of firms when firms = id_131 and missing otherwise, then you could

* For a string variable
gen firm1_s = firms if firms =="id_131"

* For a numeric variable
gen firm1_n = 1 if firms == "id_131" 
label define firlbl 1"id_131"
label values firm1_n firlbl

Hope this helps 

Ronnie 

-- 
010100100110111101101110011011100110100101100101




On Tuesday, April 24, 2012 at 4:31 AM, tashi lama wrote:

> 
> 
> 
> Hello All,
> 
> 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?
> 
> 
> Thanking, 
> 
> Tashi 
> 
> 
> *
> * 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