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.

# Re: st: question about defining a local

 From Daifeng He To statalist@hsphsun2.harvard.edu Subject Re: st: question about defining a local Date Sat, 12 Nov 2011 19:52:16 -0500

```Figured it out myself.  I need to have a compound quote because what's
in my local has already double quotes.  So this works:

local state & st=="CA"
di `"`state'"'

Thanks for all.
Daifeng

On Sat, Nov 12, 2011 at 6:08 PM, Daifeng He <dhe.statlist@gmail.com> wrote:
> Hi there,
>
> This is driving me nuts, but I just cannot see what's going wrong with
> my simple code.  Basically, I am defining a local to do sample
> restriction so that I can quicky switch from one sample restriction to
> another in my regressions.   Can anyboday tell me why my code below is
> wrong?
>
> . local state & st=="CA"
>
> . di "`state'"
> & st==CA"" invalid name
> r(198);
>
>
> But then this local is valid when I put it in a regression! (But I
> cannot use this local as an argument in a sub-program which is called
> by the main program. I am running many repeated sets of regressions so
> it's much easier to put the set of regressions into a sub-program and
> call the sub-program. The error message similar to the above. )
>
> . xtreg `depvar' `indepvar' `ctr' i.year i.qtr   if keep6_all==1
> `inrange' & capped==0  `state'  , i(id) fe
>
> Fixed-effects (within) regression               Number of obs      =    173493
> Group variable: id                              Number of groups   =      7025
>
> R-sq:  within  = 0.0757                         Obs per group: min =        13
>        between = 0.7942                                        avg =      24.7
>        overall = 0.7349                                        max =        25
>
>                                                 F(15,166453)       =    909.48
> corr(u_i, Xb)  = 0.7029                         Prob > F           =    0.0000
>
> ------------------------------------------------------------------------------
>     cenmcaid |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
> -------------+----------------------------------------------------------------
>  qmavgz_post |    .729194   .2207647     3.30   0.001     .2964999    1.161888
>       qmavgz |  -1.728832   .1877174    -9.21   0.000    -2.096754    -1.36091
>         govt |   1.379419   .5905301     2.34   0.019     .2219923    2.536845
>     nfprofit |   .5900255   .2484427     2.37   0.018     .1030833    1.076968
>          llc |  -22.47875   12.24045    -1.84   0.066    -46.46976    1.512259
>        lbeds |   .3015509   .0027418   109.98   0.000     .2961771    .3069247
>
> (the rest of results supressed)
>
>
>
>
> Daifeng
>
> *
> *   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/
```