help for mfxrcspline -------------------------------------------------------------------------------

Title

mfxrcspline -- Displays the marginal effect of a restricted cubic spline.

Syntax

mfxrcspline [if] [in] , [ at(var = # [var = # [...]]) link(linkname) customdydxb(dydxb_specification) showknots ciopts(rarea_options) noci level(#) lineopts(line_options) addplot(plot) generate(newvar1 [newvar2 newvar3]) ]

Description

mfxrcspline displays a graph of the marginal effect of a restricted cubic spline. In other words, it shows for each value of the spline variable how much the expected value of your explained variable changes for a unit change in the spline variable. It is the first derivative of the curve shown by adjustrcspline.

mfxrcspline will automatically compute the appropriate marginal effects (i.e. detect the appropriate link function) for the following commands: regress, logit, logistic, betafit, probit, poisson, cloglog, and glm (with the exception of the negative binomial link function). For other commands users can specify the appropriate link function using the link() option. With the link() option you can specify the dentity, logit, probit, log, log-complement, log-log, complementary log-log, reciprocal, power, and the odds power links. If your model uses another link function you can manually specify the first derivative of the inverse link function (with respect to the linear predictor) in the customdydxb() option.

Options

at(var = # [var = # [...]]) specifies the values of the other explanatory variables (and offset or exposure) at which the marginal effects are calculated. The default is to set all variables at their mean.

The only exception is the default when the exposure() option is specified in the estimation command. In that case the default is to set the exposure equal to the exp(mean(offset)).

link(linkname) specifies the link function used for computing the marginal effects. The link functions that can be specified are: identity, logit, probit, log, logcomplement, loglog, cloglog, reciprocal, power #, opower #. These link functions are described in [R] glm and (Hardin and Hilbe 2001).

customdydxb(inv_link_specification) specifies a user specified first derivative of the inverse link funtion. The syntax is the same as in predictnl, in particular the linear predictor can be specified with xb().

showknots specifies that the positions of the knots be shown on the graph by vertical lines.

ciopts(rarea_options) specifies options of twoway rarea to tune the display of the confidence interval.

noci suppresses the display of the confidence interval.

level(#) specifies a confidence level to use for confidence intervals. See help on level.

lineopts(line_options) specifies options of twoway line to tune the display of the point estimates of the marginal effect. These options can also be added directly, which can be convenient to change for instance the legend, axis titles, etc.

addplot(plot) provides a way to add other plots to the generated graph. See help on addplot_option.

generate(newvar1 [newvar2 newvar3]) specifies that the values of the marginal effects and optionally the lower and upper bounds of the confidence interval be saved in newvar1, newvar2 and newvar3 respectively.

Examples

sysuse nlsw88, clear recode grade 0/5=5 mkspline2 grades = grade, cubic nknots(3) logit never_married grades* adjustrcspline, name(__ex_adjustrcspline1) mfxrcspline, name(__ex_mfxrcspline1)

(click to run)

sysuse uslifeexp, clear mkspline2 ys = year, cubic reg le ys* if year != 1918 adjustrcspline if year != 1918, /// addplot(scatter le year if year != 1918, msymbol(Oh) || /// scatter le year if year == 1918, msymbol(X) ) /// ytitle("life expectancy") /// name(__ex_adjustrcspline 2) /// note("1918 was excluded from the computations because of the Spanish fl > u") mfxrcspline if year != 1918, name(__ex_mfxrcspline2)

(click to run)

sysuse nlsw88, clear recode grade 0/5=5 mkspline2 grades = grade, cubic nknots(3) logit never_married grades* local mu "1/(1+exp(-1*xb()))" local dydxb "`mu'*(1-`mu')" adjustrcspline, customdydxb("`dydxb'")

(click to run)

sysuse nlsw88, clear recode grade 0/5=5 mkspline2 grades = grade, cubic nknots(3) glm never_married grades* south, link(cloglog) family(binomial) mfxrcspline, at(south=0)

(click to run)

sysuse cancer, clear gen long id = _n stset studytime, failure(died) id(id) stsplit t, every(1)

mkspline2 ts=t, cubic nknots(3) xi: streg i.drug age ts*, dist(exp) mfxrcspline , at(_Idrug_2=0 _Idrug_3=0) /// link("log") /// noci /// ytitle(d hazard / d time)

(click to run)

Author

Maarten L. Buis Universitaet Tuebingen Institut fuer Soziologie maarten.buis@ifsoz.uni-tuebingen.de

Suggested citation if using mfxrcspline in published work

mfxrcspline is not an official Stata command. It is a free contribution to the research community, like a paper. Please cite it as such.

Buis, Maarten L. 2009. "POSTRCSPLINE: Stata module containing post-estimation commands for models using a restricted cubic spline" http://ideas.repec.org/c/boc/bocode/s456928.html

Also see

If installed: mkspline2, adjustrcspline, rcspline