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

st: RE: removing blanks in string variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: removing blanks in string variable
Date   Thu, 16 Jan 2003 12:57:43 -0000

Daniel M�ller
>
> I have a string variable, which looks like "12 34 56 78".
> How can I remove
> the blanks to obtain "12345678" ? I guess it can be done with -gen
> x=subinstr(s1,s2,s3,n), but I do not get the syntax
> correct. I checked the
> archives and the FAQs without success.

Stata < 8
=========

gen str8 x = subinstr(s1," ","",.)

This takes your example literally. More general is

gen str1 x = ""
replace x = subinstr(s1," ","",.)

Stata 8
=======

The "str8" is optional.

gen x = subinstr(s1," ","",.)

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