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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Problem with local macro command and marginsplot


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Problem with local macro command and marginsplot
Date   Fri, 7 Jun 2013 09:36:38 +0100

I see no evidence here that implies a bug. It's much more likely that
there is a problem with your understanding of local macros.

First off, there is a big difference between

local m_x r(p50)

which assigns the text "r(p50)" to the local macro, regardless of (1)
whether r(p50) currently is defined (2) what its current value may be

and

local m_y = r(p50)

which assigns the current numeric value of r(p50) (which might be
missing). Stata will never complain that r(p50) is undefined; invoking
r(p50) is never a syntax or logic error, but if the result is missing,
commands downstream may produce puzzling results.

Second,  if local macro -foo- is defined

di ` foo '

with extra spaces won't -display- it. You must type `foo'.

A quick way to check what is defined among local macros -- in addition
to -display- -- is the command -mac li-.

I don't understand your question about -margins-. The report "it works
but I got an error" needs to be fleshed out with complete and exact
detail.

Nick
njcoxstata@gmail.com


On 7 June 2013 08:38, Baruffaldi Stefano Horst
<stefano.baruffaldi@epfl.ch> wrote:

> I have a problem with the local macro command. I really tried everything and I cannot find any logic for this problem – unless it is a bug.
> I could find no previous post that addressed a similar issue.
>
> I am running the following command:
>
> sum x, d
> local m_x r(p50)
> local low_x r(p25)
> local high_x r(p75)
>
> sum y, d
> local m_y = r(p50)
> local high_y = r(p25)
> local low_y = r(p75)
>
> qui: xtreg vardep  c.y ##c.x, fe
> margins, at(x=(0(0.5)12) prior_diffy=( `low_y' `m_y' `high_y')) post
> marginsplot, xlabel(0(0.5)12) xline(` low_x ' ` m_x '  ` high_x ')
>
> right after the margins command I get the error message: “invalid numlist” or “invalid numlist has too few elements”.
>
> After a while I figured out that probably the problem is the local command: if I type for instance [dis `m_y'] it shows that there is no value stored. But the most weird thing is that if I run [dis `m_y'] right after the sum command sometimes there is the value (sometimes not, especially if I run the command directly from the do-file). In any case, after I run the margins command (whether with post option or not) the “locals” are always empty. Furthermore I used a similar code in the past without problems.
>
> This is my main problem.
> Additionally, I was wondering if there is a way to indicate directly in the margins command the percentiles of the variable I want to be considered.
> I tried with:
>
> margins, at( (p25) y  x=(0(0.5)12)) ///
>         at( (p50) y x=(0(0.5)12)) ///
>         at( (p75) y  x=(0(0.5)12))
>
> it works but I got an error after the marginsplot command saying that something more was expected
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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