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, is already up and running.

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

Re: st: efficient way to use local

From   Nick Cox <>
Subject   Re: st: efficient way to use local
Date   Mon, 25 Feb 2013 21:33:24 +0000

Efficiency I take to refer usually to machine time or storage
required, but concise code can be good too.

Rodrigo's questions raised the matter of how he is trying to learn
this. It seems that many users don't know, or have forgotten, that the
User's Guide contains a fairly complete introduction to all the
essentials here. Starting at 18.3, in a few pages you get up to macros
nested within macros, which Rodrigo was unsure about.


On Mon, Feb 25, 2013 at 8:35 PM, Rodrigo Briceño <> wrote:
> Thanks to Daniel Klein and Rebeca Pope for their insights. By
> efficient I mean with the shorter amount of lines of code, since I
> have to continue my programming routine for these 4 regressions with
> some adittional tests and graphs.
> Thanks again!
> 2013/2/25 daniel klein <>:
>> It is not clear to me, what is meant by "efficient" here, but these
>> five lines of code are the most efficient way in terms of characters
>> typed, that I can come up with
>> forv j = 1/2 {
>>         loc `j' reg il`j't pmv`j't dr1 dr2 dpl`j't
>>         ``j'' if (mon == 1)
>>         ``j'' if (mon == 2)
>> }
>> Of course, the three minutes I needed to figure this out would have
>> been sufficent to just type the four -regress- commands you want to
>> run ...
>> Best
>> Daniel
>> --
>> Dear Stata users. I am dealing with a dataset that has two slightly
>> sets of explanatory and dependent variables. The sets are defined by
>> having a 1 or 2 number inside their names and also a 1 or 2 number
>> inside the values of one of the variables. My dependents are il1t and
>> il2t. The values on the variable mon are 1 and 2. So in total my
>> output is composed by 4 regressions (one for each 1 and 2t, and one
>> for each mon value).
>> I tried to do the following:
>> local X1 "mc pmv1t dr1 dr2 dpl1t"
>> local X2 "mc pmv2t dr1 dr2 dpl2t"
>>         forvalues i= 1 2{
>>         regress il`i't `X`i' if mon=`i'
>> }
>> but I got the error: invalid syntax r(198). I am not sure if you can
>> use a local inside a local as I expressed on `X`i'

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index