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.

# Re: st: Use of -marginsplot- to plot predicted non linear combination of coefficients

 From Maarten Buis To statalist@hsphsun2.harvard.edu Subject Re: st: Use of -marginsplot- to plot predicted non linear combination of coefficients Date Mon, 13 Feb 2012 10:51:13 +0100

```On Sun, Feb 12, 2012 at 5:47 PM, Charles Vellutini wrote:
> Dear statalisters,
>
> I am running the following regression:
>
>        regress lnq lnp
>
> and use the coefficient on lnp to compute the following scalar:
>
>        scalar pxopt = CFT*(_b[lnp]/(1+_b[lnp]))
>
> where CFT is a scalar, not a variable (important).
>
> Next, running
>
>        margins,  expression(CFT*(_b[lnp] /(1+_b[lnp] )))
>
> produces the confidence interval for the scalar pxopt, which is already very convenient:
>
> ------------------------------------------------------------------------------
>             |            Delta-method
>             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
> -------------+----------------------------------------------------------------
>       _cons |    15.7541   .2571406    61.27   0.000     15.25011    16.25808
> ------------------------------------------------------------------------------
>
> What I would like is a plot of pxopt, with confidence intervals, at varying values of CFT, say over [5,20]. I have been trying to -generate- an adhoc CFT variable to play with -margins- options (particulary -over()-) and -marginsplot-, all to no avail. It is possible with these commands for what I want? Other commands (maybe -nlcom-, but I would then need to create the graph manually I guess)?

This is how I would solve that problem:

*----------------- begin example --------------------
sysuse nlsw88, clear
gen lnw = ln(wage)

reg lnw lng
est store reg

matrix res = J(151, 4, .)
matrix colnames res = cft b lb ub
local j = 1

_dots 0, title(different margins) reps(151)
forvalues i = 50/200 {
local cft = `i'/10
capture margins, ///
expression(`cft'*(_b[lng] /(1+_b[lng] ))) post
nois _dots `j' `=_rc'
local lb = _b[_cons] - invnormal(0.975)* _se[_cons]
local ub = _b[_cons] + invnormal(0.975)* _se[_cons]
matrix res[`j++',1] = (`cft', _b[_cons], `lb', `ub')
qui est restore reg
}

svmat res, names(col)

twoway rarea lb ub cft, astyle(ci) ||  ///
line b cft, lpattern(solid)     ///
legend(order(1 "95% conf. int." ///
2 "b" ))
*------------------ end example ---------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------

*
*   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/
```