Bookmark and Share

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

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

st: Problem with local macro command and marginsplot

From   Baruffaldi Stefano Horst <>
To   "" <>
Subject   st: Problem with local macro command and marginsplot
Date   Fri, 7 Jun 2013 07:38:33 +0000

Dear all,
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
Hope someone can help me.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index