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: Getting rid of units in string variable


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Getting rid of units in string variable
Date   Sun, 19 Sep 2010 08:27:28 +0200

<>

***********
clear*

inp str8 weights
101.36kg      
101.5          
101.7     
102.51           
102kg
end

list, noo

replace weights =subinstr(weights, "kg", "",.)
l
***********

To preserve the units in a different variable, you might also want to
-split-.


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Kanter, Rebecca
Sent: Samstag, 18. September 2010 22:41
To: statalist@hsphsun2.harvard.edu
Subject: st: Getting rid of units in string variable

Hi,

I am in the process of converting string variables to numeric (e.g. weight
values), but many have the units entered with the numeric value...

For example,
 101.36kg      
      101.5          
      101.7     
     102.51           
       102kg

Is there an easier way to get rid of the "kg??" 
Than to have to do:
replace  var = "101.36" if var == "101.36kg" (for every entry with units
attached)

Thanks so much,
Rebecca



___________________________________________
Rebecca M. Kanter
PhD Candidate
Johns Hopkins Bloomberg School of Public Health
Department of International Health
Center for Human Nutrition
*
*   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