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: Variable Creation


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: Variable Creation
Date   Mon, 26 Apr 2010 14:35:54 -0400

try this

gen str site=substr(sitecode,3,3) if substr(sitecode,1,2)=="37"

if you want, you can then turn this into a number using -destring-

Rich

On 4/26/10 2:32 PM, [email protected] wrote:
> Dear Statalist:
> 
> I have a partial listing of the following variable, formatted as str9:
> 
> sitecode
> --------
> 37087M022
> 37087M022
> 37173M035
> 37173M035
> 370810009
> 370810009
> 370810009
> 370810009
> 370810009
> 370810009
> 370810009
> 370870035
> 370870035
> 370870035
> 370870035
> 370870035
> 
> I would like to create an additional variable, site, as follows: site = xxx if sitecode = 37xxxyyyy. Site is the 3rd, 4th, and 5th characters of sitecode. I don't know how to do this, and what's more frustrating, I don't even know what to input in order to use help.
> 
> Sorry if this is too basic, but I do appreciate any help.
> 
> reg 
*
*   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