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: margins, dydx for systems


From   Joy Wang <[email protected]>
To   [email protected]
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,
>
> I am using Stata 12.1, fully updated, s/n 5012041613. Please see the code > fragment below. I would like to test that the effect of mvalue1 in the first > equation is equal to the effect of mvalue2 in the second equation, given the
> interaction term involving the latter. In example 14 of [R] margins, it
> illustrates how one can test that the predictive mean is equal across
> equations, but I want to test an expression involving the derivative, which > in turn involves an interaction term. The below code does not work because
> expression is not a repeatable option. I know how to compute the average
> marginal effect 'by hand' from the second equation, but wondered whether the
> 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/


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