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: Outreg for asclogit
From
John Luke Gallup <[email protected]>
To
[email protected]
Subject
Re: st: Outreg for asclogit
Date
Thu, 4 Oct 2012 02:29:27 -0700
Wameq,
A more flexible solution to the problem of getting the marginal effects for -asclogit- is to move the estimates from -estat mfx-, which is the idiosyncratic command to create the marginal effects, into the r() matrices in which they are placed by -margins-, the command that calculates marginal effects for almost all other estimation commands. Then one can use -outreg- directly to put marginal effects in a formatted table, with access to all of -outreg-'s options.
There are a couple of hoops: only rclass programs can place values in r() matrices and the marginal effects from -estat mfx- must be reorganized.
The following code does the trick:
webuse choice, clear
qui asclogit choice dealer, case(id) alternatives(car) casevars(sex income)
qui estat mfx, at(sex=0 dealer=1)
capture program drop Fill_rbV
program Fill_rbV, rclass
args b V
return matrix b = `b'
return matrix V = `V'
return local cmd "margins"
end
local k = e(k_alt)
forvalues i = 1/`k' {
tempname b`i' V`i'
mat `b`i'' = r(`e(alt`i')')
mat `V`i'' = diag(`b`i''[.,2..2])
mat `V`i'' = `V`i'' * `V`i''
mat `b`i'' = `b`i''[.,1..1]'
}
outreg, clear
forvalues i = 1/`k' {
Fill_rbV `b`i'' `V`i''
outreg, margin merge ctitle("", "", "`e(alt`i')'") nodisplay
}
outreg using ascmfx, replay replace
The table looks like this:
-------------------------------------------------
American Japan Europe
-------------------------------------------------
dealer American 0.017 -0.012 -0.004
(2.29)* (2.34)* (1.66)
Japan -0.012 0.017 -0.004
(2.34)* (1.83) (1.03)
Europe -0.004 -0.004 0.009
(1.66) (1.03) (1.30)
casevars sex* 0.026 -0.161 0.135
(0.38) (2.03)* (1.76)
income -0.008 0.006 0.002
(2.95)** (1.96) (1.14)
N 885 885 885
-------------------------------------------------
John
On Oct 2, 2012, at 9:39 PM, John Luke Gallup <[email protected]> wrote:
> Wameq,
>
> -outreg- (and probably -outreg2- and -estout-) don't handle marginal effects after -asclogit- because the results are saved in a very non-standard format.
>
> -estat mfx-, which is only for use after -asclogit- saves the marginal effects in r() matrices named after the logit categories.
>
> Things you can't do in -outreg- you can still do with a bit of work with -frmttable-, which is the formatting engine distributed with -outreg-.
>
> The following code creates an -outreg- compatible table (which can be merged, etc.) showing the marginal effects with t-statistics below them and asterisks for significance.
>
> First I calculate the marginal effects:
>
> webuse choice, clear
> asclogit choice dealer, case(id) alternatives(car) casevars(sex income)
> estat mfx, at(sex=0 dealer=1)
>
> Then I create a Stata matrix holding the marginal effects and t-stats (`b') and an indicator matrix for where the stars go (`stars', using the mata command). These are passed to -frmttable- to create a Word table (or TeX table) with the results.
>
> tempname b stars
> loc ctitl `""","""'
> forvalues i = 1/`e(k_alt)' {
> tempname b`i'
> mat `b`i'' = r(`e(alt`i')')
> mat `b' = (nullmat(`b'), `b`i''[.,1..1], `b`i''[.,3..3])
> mat `stars' = (nullmat(`stars'), `b`i''[.,4..4])
> loc ctitl `"`ctitl' ,`e(alt`i')'"'
> }
> mata: st_matrix("`stars'", (abs(st_matrix("`stars'")):<0.05) + ///
> (abs(st_matrix("`stars'")):<0.01))
> frmttable using ascmfx, statmat(`b') substat(1) ///
> annotate(`stars') asymbol("*","**") ctitle(`ctitl') ///
> replace note("* p<0.05; ** p<0.01")
>
> You could adapt this to report standard errors, p-values, or change the stars, etc. if you want.
> Here's the table:
>
> ---------------------------------------------------
> American Japan Europe
> ---------------------------------------------------
> dealer American 0.02* -0.01 -0.00
> (2.29)* (-2.34) (-1.66)
> Japan -0.01* 0.02 -0.00
> (-2.34) (1.83) (-1.03)
> Europe -0.00 -0.00 0.01
> (-1.66) (-1.03) (1.30)
> casevars sex* 0.03 -0.16 0.13
> (0.38)* (-2.03) (1.76)
> income -0.01** 0.01 0.00
> (-2.95) (1.96) (1.14)
> ---------------------------------------------------
> * p<0.05; ** p<0.01
>
>
> John
>
>
> On Oct 2, 2012, at 1:38 PM, Wameq Raza <[email protected]> wrote:
>
>> Hi everyone,
>> I was wondering if anyone could kindly tell me if there's a way to get
>> the marginal effects of a asclogit model that I'm running
>> into a table using outreg.
>> More specifically, I'm generating the marginal effects using: estat
>> mfx, var (variables); i'm doing this for both alt specific and
>> case specific vars.
>> Any help would be much appreciated!
>> Best
>> Wameq
>>
>> --
>> W A M E Q R A Z A
>> *
>> * 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/
>
*
* 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/