Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: RE : st: RE : st: RE : st: Do-file no result, command line OK


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: RE : st: RE : st: RE : st: Do-file no result, command line OK
Date   Tue, 29 Mar 2011 14:49:15 +0100

It all becomes clearer.

Your -replace- statements should refer to `var'_2, etc. -- otherwise
you will necessarily lose the changes that you made within the
original -generate- statement.

That is, you take -make- and remove the spaces and that is a new
variable. Then your new variable is -replace-d by an operation on the
original variable. All the changes made in the -generate- will be
ignored as you overwrite all values.

I suspect that the difference between do-file and interactively was
not the issue. You were not issuing the same code.

Nick

On Tue, Mar 29, 2011 at 2:35 PM,  <[email protected]> wrote:
> I reproduce below two do-files which are similar to mine. The first one works fine, we get rid of the dot. However, the second one, which differs from the 1st one just because a command line has been added, doesn't work any more. This the thing I do not understand.
>
> *** Option 1
> sysuse auto
> global variables make                   // I have two variables in the original do-file
> foreach var in $variables {
> gen `var'_2 = subinstr(`var', " ", "", .)
> replace `var'_2= subinstr(`var', ".", "", .)
> }
>
>
> **** Option 2
> global variables make                   // I have two variables in the original do-file
> foreach var in $variables {
> gen `var'_3 = subinstr(`var', " ", "", .)
> replace `var'_3= subinstr(`var', ".", "", .)
> replace `var'_3= subinword(`var', "Chev", "", .)
> }
> browse
> ************
>
> Best,
>
> Xavier
>
> -------- Message d'origine--------
> De: [email protected] de la part de Nick Cox
> Date: mar. 29/03/2011 14:20
> À: [email protected]
> Objet : Re: st: RE : st: RE : st: Do-file no result, command line OK
>
> That does not make sense.
>
> ... if variable == "."
>
> can't be satisfied by values such as "BP P.L.C." as they are not equal to ".".
>
> Either you mean something else, or your copy of Stata is hopelessly corrupted.
>
> Nick
>
> On Tue, Mar 29, 2011 at 2:11 PM,  <[email protected]> wrote:
>
>> Unfortunately not. - browse if variable=="." - gives observations such as:
>> BP P.L.C.
>> However, once I copy and past the line in the command line instead of running the dofile, I get:
>> BP PLC

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index