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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: Variable Creation


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Variable Creation
Date   Mon, 26 Apr 2010 20:45:12 +0200

<>

" I don't even know what to input in order to use help."


The solution in these cases is always hidden in -help string functions-. A judicious application of the functions assembled there solves almost all of these problems:

*******
clear*

inp str9 sitecode
37087M022
37087M022
37173M035
37173M035
370810009
370810009
370810009
370810009
370810009
370810009
370810009
370870035
370870035
370870035
370870035
370870035
end

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

format site %03.0f

list, noo
*******


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of drreg@earthlink.net
Sent: Montag, 26. April 2010 20:33
To: statalist@hsphsun2.harvard.edu
Subject: st: Variable Creation

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/


*
*   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