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

Re: st: space trouble in excel to stata conversion

From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: space trouble in excel to stata conversion
Date   Fri, 03 Oct 2008 12:12:39 +0100

Ashim Kapoor wrote:
> Hello,
> I posted about this a couple of days ago.
> Let me tell you my problem. I have a string variable , sometimes at
> the end of many  observations  I seem to have an extra space character
> which does not go away when I use trim.
> Also I have tried adding a " dummy" to all the observations and then
> doing an itrim. But some observations continue to have 2 spaces
> between the 2nd last and last word. Nothing seems to be working!
> Any tips ?
Further the above seems to describe two separate problems.  In the first
instance you are saying that you have unwanted spaces at the end of
observations, but then you go on to describe double spaces between words
within a variable.

So is it that you have a variable with observations 'foo bar ' (<-- note
space at end) or is it that you have observations with 'foo  bar'
(<---note the double spaces between words within the observation).

If its the former then there is no reason why the -trim()- function
won't work.  If its the later then -trim()- won't work at removing the
double spaces since it only acts on spaces at the start or end of a
variable, and instead you should look at using -subinstr([varname], " 
", " ")- to replace double spaces to single spaces.

If you've a mixture of the two examples then you can use
-trim(subinstr([varname], "  ", " "))- to do both in one step.


"We should make things as simple as possible, but not simpler" - Anon (not Albert Einstein)

This  message  may  contain  confidential and  privileged  information.
If you  are not the  intended recipient  you should not  disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents.  To do so is strictly  prohibited and may be unlawful.
Please  inform  the  sender that  this  message has  gone astray before
deleting it.  Thank you.

2008 marks the 60th anniversary of the NHS.  It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS  and  would like  an NHSmail  email account, go

*   For searches and help try:

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