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: Bug? Margins Row Names


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: Bug? Margins Row Names
Date   Mon, 31 Oct 2011 09:11:05 -0500

Joseph Daniel Wolfe <[email protected]> is consuming the -r(at)- matrix
posted by -margins- and asks about the attached row names:

> I'm writing a program where I use the row names of r(at) after margins.
> I'm running into an odd problem.  Whenever I have more than 1 row,
> "1bn._at" and "2._at" is returned as the row names when the matrix
> displays "1._at" "2._at." This issue does not occur when I have only 1
> row, i.e., "1._at" is returned as the row name.
> 
> For example: 
> 
> **********************************
> // Info about my copy of Stata
> //  - Stata/IC 12.0 for Mac (64-bit Intel)
> //  - Revision 13 Oct 2011
> 
> version 12.0  
> sysuse cancer
> 
> // 1.  Incorrect Row 1 Name
> logit died studytime drug age
> margins, at(drug=(0 1))
> local rnames : rownames r(at)
> di `"rnames: `rnames'"'
> 
> // 2.  Correct Row 1 Name
> margins, at(drug=(0))
> local rnames : rownames r(at)
> di `"rnames: `rnames'"'
> **********************************
> 
> Is this a bug or am I missing something here?  Thank you so much for any
> response. 

This is not a bug.

-margins- is storing the factor levels of a pseudo-variable called '_at', but
this factor variable does not have a base level.  The 'bn' in '1bn._at' means
no base level.

-matrix list- does not report the absence of a base level in factor variables
in the row or column titles.

Joseph does not indicate how this is causing trouble, but I can suggest a
simple substitution within the 'rnames' macro.

Joseph can use -:subinstr- to substitute '1._at' for '1bn._at':

	logit died studytime drug age
	margins, at(drug=(0 1))
	local rnames : rownames r(at)
	di `"rnames: `rnames'"'
	local rnames : subinstr local rnames "1bn._at" "1._at"
	di `"fixed rnames: `rnames'"'

--Jeff
[email protected]
*
*   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