Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: a little string question.


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: a little string question.
Date   Wed, 8 Oct 2003 18:29:03 +0100

[email protected]

> I have a string variable (caseid) coded on the format :
> 
> . codebook caseid
> 
> 
> caseid ---------------------------------------------------- 
> Case Identification
>                   type:  string (str16), but longest is str15
> 
>          unique values:  3109                 coded 
> missing:  0 / 3552
> 
>               examples:  "7 2 177 43  2"
>                          "1210  51140  2"
>                          "1831 105 76  5"
>                          "2647   3 40  2"
> 
> 
> I want:  72177432
>             1210511402
> etc.,
> 
> I use the command: g newid=trim(caseid)
> but it returns a type mismatch error.
> 
> The real() and destring commands don't work and the encode 
> one leaves blanks as 
> caseid.

I guess that you are using Stata 7. 

The reason that 

. g newid = trim(caseid) 

doesn't work is that by default -generate- expects to find 
a numeric argument. However, -trim- does no good 
here because it won't do anything to the spaces 
in the middle of strings. Similarly -real()- won't help 
here because of the internal spaces. 

-destring- _should_ help here. 

You need 

destring caseid, generate(newid) ignore(" ") 

Nick 
[email protected] 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index