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]

From |
Joy Wang <jwang@stata.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: margins, dydx for systems |

Date |
Wed, 14 Nov 2012 15:02:22 -0600 |

Kit Baum inadvertently sent the following question to Statalist: > Dear tech support, >

> interaction term involving the latter. In example 14 of [R] margins, it > illustrates how one can test that the predictive mean is equal across

> expression is not a repeatable option. I know how to compute the average

> margins apparatus was capable of doing so itself, as it is in many other > circumstances. > > webuse grunfeld,clear > keep if company<3 > reshape wide invest mvalue kstock, i(year) j(company) > sureg (invest1 kstock1 mvalue1) (invest2 c.kstock2##c.mvalue2) > margins, dydx(_all) expression(predict(equation(invest1))) /// > expression(predict(equation(invest2))) post I responded to Kit privately, but because the solution to this question may be of interest in general, I would like to share it here as well. --------------------------------------------------------------------------------------------------- It is correct that -margins- doesn't allow more than one -expression()- option. Having said that, it is possible to compare these marginal effects. Because the two linear equations don't have common independent variables in this particular example, the -margins- command below that uses a single -expression()- option and specifies a summation of the two equation predictions will produce the marginal effects for the two equations. ********************** webuse grunfeld,clear keep if company<3 reshape wide invest mvalue kstock, i(year) j(company) qui sureg (invest1 kstock1 mvalue1) (invest2 c.kstock2##c.mvalue2) margins, dydx(_all) post /// expression(predict(equation(invest1))+predict(equation(invest2))) test mvalue1 = mvalue2 *********************** A more direct approach, and one that can be used when there are common variables between the two equations, is stacking the Jacobian matrices from the separate marginal effects to produce the covariance matrix of the stacked separate marginal effects. Here is the (rather more involved) stacked version: *********************** webuse grunfeld,clear keep if company<3 reshape wide invest mvalue kstock, i(year) j(company) qui sureg (invest1 kstock1 mvalue1) (invest2 c.kstock2##c.mvalue2) margins, dydx(_all) expression(predict(equation(invest1))) matrix b1 = r(b) matrix coleq b1 = invest1 matrix J1 = r(Jacobian) matrix list b1 matrix list J1 margins, dydx(_all) expression(predict(equation(invest2))) matrix b2 = r(b) matrix coleq b2 = invest2 matrix J2 = r(Jacobian) matrix list b2 matrix list J2 matrix b = b1, b2 matrix J = J1 \ J2 matrix V = J*e(V)*J' matrix colna V = `:colfullna b' matrix rowna V = `:colfullna b' capture program drop POSTIT program POSTIT, eclass ereturn post b V end POSTIT test [invest1]mvalue1 = [invest2]mvalue2 *********************** Best wishes, -- Joy Wang Statistician StataCorp * * 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/

**References**:**st: margins, dydx for systems***From:*Christopher Baum <kit.baum@bc.edu>

- Prev by Date:
**Re: st: How can I fill in missing values for the month or quarter in this** - Next by Date:
**Re: st: Mandelbrot sets** - Previous by thread:
**st: margins, dydx for systems** - Next by thread:
**[no subject]** - Index(es):