Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: graph mean and sd over/by category

From (Vince Wiggins, StataCorp)
Subject   Re: st: graph mean and sd over/by category
Date   Mon, 10 Feb 2003 16:55:20 -0600

Among other things, George Hoffman <> asks,

> [...] fitted curves under scatter plots look beautiful - can the
> regression coefficients from fplotci or qplotci be captured somehow,
> as poor-man's curve fit?

I think George is referring to the -fpfitci- and -qfitci- plot types of 
-graph twoway-.  If so, he can readily perform the regressions that produced
the graphs.

-qfitci- just performs a quadratic regression.  If we use the auto data,
-sysuse auto-, the lines for the graph command,

      . twoway qfitci mpg weight

are the predictions of the quadratic fit,

      . gen weight2 = weight^2
      . regress mpg weight weight2

The coefficients can be seen in the output of -regress-, or manipulated in the
usual way through the saved results.

If George wants to add the predictions, and their CIs to his dataset, he can

      . predictnl mpg_hat2 = predict() , ci(ci_low ci_high)

This is a very simple application of -predictnl-, Bobby Gutierrez
<> said more in a prior post, but it lets us get both the
predictions and their CIs with one command.

We could then get a graph similar to our earlier -twoway qfitci-, by typing,

      . twoway rarea ci_low ci_high weight, sort || line mpg_hat2 weight, sort

which we will immediately think looks ugly and decide to relabel the CI in the
legend, option -legend(label())-, and change the fill color of the CI to be
the standard for our scheme, option -p(ci)-.

      .  twoway rarea ci_low ci_high weight , sort p(ci) || 
                line mpg_hat2 weight , sort legend(label(1 "CI"))

The -fpfitci- plot type just uses -fracpoly- as the engine to produce the
fits, much like -regress- is used for the quadratic fit.  For our example, the
corresponding -fracpoly- estimation command is,

      . fracpoly regress mpg weight

and we can repeat the rest of the story, or just use -fracplot-, to plot the
fit and CI.

-- Vince

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index