Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Normally distributed error term & testing normality of residuals

From   Maarten Buis <>
Subject   Re: st: Normally distributed error term & testing normality of residuals
Date   Tue, 16 Oct 2012 09:52:24 +0200

On Mon, Oct 15, 2012 at 6:56 PM, Seed, Paul wrote:
> I might add that I generally work on the raw data, not the residuals, as it is easier to
> understand the qnorm plot and the transformation needed; and I'm not interested in testing the
> residuals formally.

The problem with that is that Ebru is working in a regression like
context, and we would not expect the raw data to be
normally/Poisson/Gamma/... distributed when there are explanatory
variables involved. The marginal distribution of the
dependent/explained/left-hand-side/y-variable can deviate considerably
from the distribution that gives your regression model its name. This
is what I wrote the -margdistfit- package for. To borrow an example
from my talk at the 2012 German Stata Users' meeting

*------------------------- begin example ---------------------------
// create random data made for a linear regression
set seed 12345
clear all
set obs 1000
gen x = _n < 250
gen y = 0 + 3*x + rnormal()

// show that y is not normally distributed
qnorm y, name(qnorm, replace)

// A more fancy version of the previous graph
// requires -qenv- (SSC) and -qplot- (SJ)
qenvnormal y, gen(lb ub) reps(1000)
sum y
local l = `r(mean)' + `r(sd)' * invnormal((     1 - .5)/`r(N)')
local u = `r(mean)' + `r(sd)' * invnormal((`r(N)' - .5)/`r(N)')

qplot y lb ub, ms(oh none ..) c(. l l) lc(gs10 ..) legend(off)  ///
        ytitle("y") trscale(`r(mean)' + `r(sd)' * invnormal(@)) ///
        xtitle(Normal quantiles) ylab(-6(2)8) xlab(-6(2)8)      ///
        aspect(1) name(gauss, replace)                          ///
        addplot(function y = x, range(`l' `u')                  ///
                lpattern(solid) lc(gs10))

// show that the distribution of y corresponds with
// the marginal distribution implied by -regress-
// requires -margdistfit- (SSC)
reg y x
margdistfit , qq name(marg, replace)
*-------------------------- end example ----------------------------
(For more on examples I sent to the Statalist see: )

Hope this works,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

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