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


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

Re: st: Bug? Margins Row Names


From   jpitblado@stata.com (Jeff Pitblado, StataCorp LP)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Bug? Margins Row Names
Date   Mon, 31 Oct 2011 09:11:05 -0500

Joseph Daniel Wolfe <jdwolfe@indiana.edu> 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
jpitblado@stata.com
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index