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: Constructing a variable from standard deviations
From
Clive Nicholas <[email protected]>
To
[email protected]
Subject
Re: st: Constructing a variable from standard deviations
Date
Mon, 22 Nov 2010 19:46:16 +0000
Maarten Buis replied to Mathijs P.J. van Zaal:
Bit late to this party, but...
[...]
> *---------------------------- begin example -----------------------
> // define linear regression model with non-constant error variance
> program drop _all
> program define mynormal_lf
> version 11
> args lnfj mu ln_sigma
> quietly replace `lnfj' = ///
> ln(normalden($ML_y1, `mu', exp(`ln_sigma')))
> end
>
> // open data
> sysuse auto, clear
> recode rep78 1/2=3
>
> // estimate a regular regression, i.e. with constant residual variance
> reg mpg weight displacement foreign i.rep78
>
> // store parameters for starting values
> tempname b0 rmse
> matrix `b0' = e(b) // effects in the mu equation
> scalar `rmse' = ln(e(rmse)) // constant of the ln_sigma equation
>
> // specify the model
> ml model lf mynormal_lf ///
> (mu: mpg = weight displacement foreign i.rep78) ///
> (ln_sigma: i.rep78)
>
> // specify the initial values
> ml init `b0'
> ml init ln_sigma:_cons = `= `rmse' '
>
> // maximize the likelihood
> ml maximize
>
> // predict the residual variances
> predict sigma, xb eq(ln_sigma)
> replace sigma = exp(sigma)
>
> // display the residual variances
> // the residual variance is constant within each category of rep78
> table rep78, c(mean sigma)
> *---------------------------- end example --------------------------
...on my Stata 9.2, this code choked at
. // estimate a regular regression, i.e. with constant residual variance
. reg mpg weight displacement foreign i.rep78
i: operator invalid
r(198);
and at all other parts of the code which feature -i.rep78-
--
Clive Nicholas
[Please DO NOT mail me personally here, but at
<[email protected]>. Please respond to contributions I make in
a list thread here. Thanks!]
"My colleagues in the social sciences talk a great deal about
methodology. I prefer to call it style." -- Freeman J. Dyson.
*
* 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/