[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/