If you are getting a type mismatch error, you must be using Stata 7 or
earlier (Stata 8 will generate a string as needed). You would need to type
:
g str15 newid=trim(caseid)
except this won't do what you want since trim will only trim from the
beginning and end, not the middle. You need to use subinstr:
gen str15 newid=subinstr(caseid," ","",.)
would eliminate all single spaces within the text.
Michael Blasnik
[email protected]
----- Original Message -----
From: <[email protected]>
To: <[email protected]>
Sent: Wednesday, October 08, 2003 1:16 PM
Subject: st: a little string question.
> Dear stata users,
>
> 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.
>
> Can somebody helps?
>
> Cheers.
>
> Amadou.
*
* 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/