Statalist The Stata Listserver


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

RE: st: Substring command


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Substring command
Date   Sun, 23 Apr 2006 16:28:11 +0100

This is a round-about solution
offering no advantage over 
the one-line solution already given by 
Austin. Austin's is more general, and 
thus preferable. 

As previously pointed out in this thread, 
if you are inclined to use -destring-, just 

. destring a, ignore(-) replace 

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

victor michael zammit
 
> The following will work :
> 
> input str9 a
> 100-2555
> 500-2341
> 564-5213
> end
> gen aa = substr(a,1,3)+substr(a,5,4)
> destring aa,gen(s)
> list
> Note that aa is string variable and s is numeric variable

Austin Nichols  
 
> > read -help strfun-
> > and try
> > . replace code = subinstr(code,"-","",.)
 
Mosca, Ilaria 

> > > I have a string variable that looks like the following:
> > > 100-2555
> > > 500-2341
> > > 564-5213
> > > I would like to generate another variable that takes away 
> the dash. In
> > > other words, the new variable would be the following:
> > > 1002555
> > > 5002341
> > > 5645213
> > >
> > > I tried with the command  --replace code = subinstr(code,"-","")
> > > But I obtain an "invalid syntax r(198)" message.
> > >
> > > What should I do?

*
*   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