Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: removing leading blanks


From   Abhimanyu Arora <abhimanyu.arora1987@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: removing leading blanks
Date   Sat, 31 Dec 2011 19:12:26 +0530

Hi Nick
Thanks for the tip.
I followed your suggestions but somehow still am unable to get things right.
Here are the steps I followed together with the displayed output.
Charlist rules out non-blank spaces, but-subinstr- with char(9) or "
", both do not yield the desired outcome.

. count
   10

. gen problem=substr(var1,1,4)

. charlist problem


. replace var1 = subinstr(var1, char(9), "", .)
(0 real changes made)


Now,

. replace var1 = subinstr(var1, " ", "",. )
(10 real changes made)

. gen problem2=substr(var1,1,3) *It seems the 10 changes are basically
left trimming by 1 leading blank space*

. charlist problem2


. replace var1 = subinstr(var1, " ", "",. ) *Similar recursive steps
as above does not seem to work out*
(0 real changes made)

Cheers
Abhimanyu



On Sat, Dec 31, 2011 at 5:34 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> What you describe as blanks may be some other character(s).
>
> -charlist- (SSC) is a utility which may help.
>
> gen problem = substr(var1, 1, 4)
>
> charlist problem
>
> After finding out which characters are present, use code such as
>
> replace var1 = subinstr(var1, char(9), "", .)
>
> where 9 is a placeholder for the argument you need. (char(9) is a tab,
> and the characters might just be a tab.)
>
> Nick
>
> On Sat, Dec 31, 2011 at 11:54 AM, Abhimanyu Arora
> <abhimanyu.arora1987@gmail.com> wrote:
>
>> All values of a string variable, var1, have 4 blank spaces in the beginning.
>> However, when I type in the command
>> -replace var1=ltrim(var1)- ,
>>  the output displays "0 real changes made" (and needless to say,
>> things remain as they were to start with)
>> Would be really great if this puzzling issue is sorted out.
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index