Statalist The Stata Listserver


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

RE: st: removing "first letters"


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: removing "first letters"
Date   Wed, 26 Apr 2006 11:39:35 +0100

This is good, but not I would say optimal. 

Suppose for example your strings really 
start with a space in some or all observations. 

Suppose you haven't spotted that a few observations
don't follow this pattern. 

If so, you will have messed up your data. 
Even if not, 

replace varname = subinstr(varname, "www.", "", 1) 

is a more focused approach to the problem. Yet 
another small advantage is that your purpose will
be clearer in do or log files. 

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

clinton.thompson@summitllc.us
 
> try the -substr- function:
> 
> gen newvarname = substr(original_variable, 5, .)
> 
> briefly, generate a new variable equal to the contents of the original
> variable, minus the first four characters (e.g. the "www.").
> 
> type -findit substr- for more information.
 
> > I have a variable with web addresses and all the entries in 
> this variable
> > start with "www.". Is there an easy way of removing the 
> "www." from the
> > beginning of all entries?

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