Statalist The Stata Listserver


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

RE: st: RE: RE: extract middle of string


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: RE: extract middle of string
Date   Tue, 24 Oct 2006 17:34:02 +0100

On a slightly different note, it has long been a concern
of mine that learning about Stata functions poses a variety 
of distinct challenges to users at various points on the 
learning curve (which is a family of curves, but let that be...). 

It's quite common to find that users suspect that a program
is needed to do something when some fairly straightforward 
application of functions will fix the problem. 

Functions fall into those you know you want -- the only 
question is what is the precise syntax -- and those you
don't know you need. The documentation in [D] is geared 
towards look-up tasks but not seemimgly to inspiring users with 
all the useful things they can do with functions. 

New functions are usually flagged very briefly 
in the opening sections of [U] or -whatsnew.hlp- and
so it is very easy for both new and experienced users
to miss the announcement or fail to register the 
possible later value of something that flashes into
consciousness briefly. New commands, which usually 
but not invariably are a bigger deal, naturally get
more coverage. 

Much of the power of functions comes when they are combined, 
which like so much else is often obvious when pointed out 
but does become much clearer on seeing examples. Combining
-substr()- with -length()- is just one instance. 

So, what does this imply? Mainly that as an Editor of 
the Stata Journal I am always on the lookout for functional
material for the Journal, mostly as Tips but also
for other pieces (thus we ran a tutorial on -cond()- 
not so long ago by David Kantor and myself). 
Suggestions of Tips are always welcome (best addressed
to editors@stata-journal.com). 

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

Ronnie Babigumira
 
> Thanks to Justin White, Jean Ries and Nick Cox for their responses.
> 
> I will settle with the solution offered by Jean and Nicks 
> because it is shorter
 
Nick Cox wrote:

> > Note that there is no longer a need to specify 
> > variable type to -generate- string variables, although
> > that does no harm. 
> > 
> > This is in essence the same question as one 
> > raised by Ari Friedman on 11 October and can 
> > be attacked directly without any need for reversing. 
> > 
> > The length of a string is given by -length()-,  
> > so everything but the last two characters is 
> > 
> > substr(x,1,length(x) - 2) 
> > 
> > and everything between the second and the 
> > last two characters is one substring with 
> > one character fewer: 
> > 
> > substr(x, 2, length(x) - 3) 
> > 
> > At some stage every serious Stata user has 
> > to browse the functions sections of the manual
> > carefully, dry though they are! 

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