[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: prediction after y-logged regression

From   "Shehzad Ali" <>
To   <>
Subject   RE: st: prediction after y-logged regression
Date   Thu, 5 Jun 2008 16:36:29 +0100

Thanks, Nick. This is helpful.



-----Original Message-----
[] On Behalf Of Nick Cox
Sent: 03 June 2008 15:33
Subject: RE: st: prediction after y-logged regression

You could try it and see. Or look at the code to see what it does. 

In fact, this won't work. -predlog- is self-contained and carries out a
regression and then does the necessary extra calculations. Only by
rewriting the program could you extend it to other methods. 

I found this in my files. Without absolutely no promises about its
scope, it may nevertheless show by example that you don't much need an
extra program, as only a few lines are required after something like a

*! NJC 1.1.0 8 January 2005 
* NJC 1.0.0 13 September 2002 
program smear, rclass  
	version 8.0
	syntax [if] [in] [, Generate(str) OUTofsample ]  

	if "`generate'" != "" { 
		capture confirm new variable `generate' 
		if _rc {
			di as err "option syntax is generate(newvar)" 
			exit _rc 

	marksample touse 
	qui count if `touse' 
	if r(N) == 0 error 2000
	tempvar resid yhatraw
	tempname rmse cf 

	qui { 
		* will exit with error message if no estimates 
		scalar `rmse' = e(rmse)
		if "`outofsample'" != "" predict double `yhatraw' 
		else predict double `yhatraw' if e(sample) 
		predict double `resid', res
		replace `resid' = exp(`resid') 
		su `resid', meanonly 
		scalar `cf' = `r(mean)'

		if "`generate'" != "" { 
			gen double `generate' = exp(`yhatraw') * `cf' if
			la var `generate' "smeared retransformation"

	di as res scalar(`cf') 
	return scalar smearcf = `cf' 

Shehzad Ali

Thanks, Richard. I understand that - predlog - is useful for OLS
What if you are using models like treatreg or heckman or other two-part
models? Would - predlog - still work?

Richard Goldstein

type -findit predlog-

Shehzad Ali wrote:
> I am running a regression in which y variable is logged 
> (semi-logarithmic). The literature suggests that in order to get an 
> anti-logged prediction of yhat, one should proceed like this:
> 1. Run the regression and predict yhat,
> 2. Then exponentiate the predicted yhat, and finally
> 3. Mutiply the exponentiated predicted yhat by the mean value of 
> residuals from the regression (otherwise known as smearing).
> I was wondering if there is a direct way to do it in stata or if there

> is any other method that experts would suggest to get anti-logged 
> prediction.

*   For searches and help try:

*   For searches and help try:

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