Statalist The Stata Listserver


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

Re: st: trim spaces in postcode


From   "Ada Ma" <heu034@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: trim spaces in postcode
Date   Fri, 31 Mar 2006 17:39:27 +0100

Actually British postcodes are all 5 to 7 characters long (excluding
space) so there is scope for saving storage by not specifying str8. 
Thanks to Emma for the -subinstr- command though, I had been using a
loop and the -substr- command to remove spaces from postcodes.  The
-subinstr- is much faster and easier to write.


On 3/31/06, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> A quibble on the side:
>
> As it happens I guess no British postcode
> is longer than 8 characters, but in
> general this is dangerous, with greater
> and lesser dangers.
>
> Forget postcodes, and consider the possible
> consequences of stipulating -str8-.
>
> If I say
>
> gen str8 whatever = "abcdefghi"
>
> Stata assumes I mean what I say
> and that I trust it to do the best
> it can.
>
> The consequence will be "abcdefgh"
> everywhere, and no warning message.
> The greater danger is thus loss of data.
>
> If I say
>
> gen str8 whatever = "foo"
>
> the consequence is "foo" everywhere
> and some wasted storage. That may be
> trivial to you, but it is still avoidable.
>
> I guess Emma has been using Stata for
> a while and started when you _had_ to
> specify a string type in generating
> a string variable. For a few versions
> past, that has no longer been compulsory.
> It is best, in fact, not to do it, as
> Stata is smarter at computing than you
> are.
>
> If I say
>
> gen something = "foo"
>
> -something- will be born -str3-.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Maurizio Gibin
>
> > Thank you Emma...
> > Easy and it's working!
>
> Emma.Slaymaker
>
> > gen str8 newvar=subinstr(oldvar," ","",.)
> >
> > if oldvar is your current postcode variable and newvar is a new one.
>
> Maurizio.Gibin
>
> > I am trying to trim all the spaces in a code, in particular an english
> > unit postcode
> > but I still haven't found the correct way. I downloaded the ptseed
> > strip function but seems is not working.
> > Can anyone please help me? The database I am working on is quite
> > huge...
>
> *
> *   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/
>


--
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926

*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index