Statalist The Stata Listserver

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

RE: st: trim spaces in postcode

From   "Nick Cox" <>
To   <>
Subject   RE: st: trim spaces in postcode
Date   Fri, 31 Mar 2006 16:36:31 +0100

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 

If I say 

gen something = "foo" 

-something- will be born -str3-. 


Maurizio Gibin
> Thank you Emma...
> Easy and it's working!

> gen str8 newvar=subinstr(oldvar," ","",.)
> if oldvar is your current postcode variable and newvar is a new one.


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

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index