Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: destring


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: destring
Date   Wed, 1 Aug 2007 22:50:59 +0100

I posted a quasi-tutorial on this general area a short while 
back. It may help understanding of the numeric <-> string 
conversion problems (and they are problems, not a single
problem). 

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.0707/Author/article-469.html>

There is no reason why -encode- should not be used. 
String variables can have embedded numeric characters. 
That's absolutely no reason against using -encode-. 
It may not help much but it is legal and a practical
possibility. 

Otherwise, I think you need to look for substrings 
like "200 MG/ML" using -strpos()- (-index()- in 
old Stata versions). The string functions are
your friend here. 

strpos(drug_1, "200 MG/ML") 

will be positive if "200 MG/ML" is included and
zero otherwise. 

-destring- is no use to you at all. 

I don't understand what an "explore variable" is. 
Explanatory? 

Nick 
n.j.cox@durham.ac.uk 

P chrisman
 
> I am having a great deal of trouble changing strings to 
> numeric. I have 
> a variable "drug_1" that  is a strg40 with 32 unique values 
> (I did not 
> create this data set!). Examples are:
> 
>                          "TESTOSTERONE CYP 200MG/ML INJ (IN OIL)  "
>                          "TESTOSTERONE ENANTH. 200MG/ML   1ML     "
>                          "TESTOSTERONE ENANTHATE 200MG/ML INJ 5ML "
>                          "TESTOSTERONE ENANTHATE 200MG/ML INJ 5ML "
>                             TESTOSTERONE (ANDRODERM) 5MG/24HRS PATCH
> 
> Drug dose is the explore variable and the PI wants to look at 
> outcome by 
> mode of administration and dose, so for the example here I 
> need to have 
> a drug_1 variable with mode 1=IM  and 2=patch and dose 200mg/ml, 
> 200mg/5ml and 5mg/24hr.
> 
> I have tried encode, but I do not think I can use that because the 
> strings also contain numbers(please correct if this is not true). I 
> tried destring with the following errors:
> 
> destring Drug_1, replace
> Drug_1 contains non-numeric characters; no replace
> 
> . destring Drug_1, replace ignore("testosterone")
> Drug_1 contains characters not specified in ignore(); no replace
> 
> I could not find anything in FAQ that was similar to this problem. I 
> would appreciate ANY HELP as I have drug_1 through drug_5 for 384 
> subjects and can do this the long and painful way, but would 
> prefer not.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index