------------------------------------------------------------------------------------------ name: log: U:\projects\misc\stata_lf_programs\tobit\tobit_expected_value.txt log type: text opened on: 31 Oct 2014, 13:25:58 . . version 13.1 . clear all . set more off . set seed 1234567 . set obs 10000 obs was 0, now 10000 . . . * Simulate data . gen x = rnormal(5, 2) . gen y = -4 + 1*x + rnormal(0,1) . gen yt = max(0, y) . sum yt y Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- yt | 10000 1.452821 1.594159 0 8.417286 y | 10000 .9556056 2.225627 -7.519608 8.417286 . . * Esimate Tobit model (i.e. latent variable). Should match above DGP . tobit y x, ll(0) Tobit regression Number of obs = 10000 LR chi2(1) = 13626.10 Prob > chi2 = 0.0000 Log likelihood = -10811.579 Pseudo R2 = 0.3866 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | .9963011 .0070562 141.20 0.000 .9824695 1.010133 _cons | -3.967395 .0413477 -95.95 0.000 -4.048445 -3.886345 -------------+---------------------------------------------------------------- /sigma | .9913134 .0086852 .9742886 1.008338 ------------------------------------------------------------------------------ Obs. summary: 3332 left-censored observations at y<=0 6668 uncensored observations 0 right-censored observations . . * Predictions based on latent variable . predict yhat (option xb assumed; fitted values) . . * Censored predictions . predict yhatstar, ystar(0,.) . . sum yhat* Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- yhat | 10000 .9682756 1.972654 -6.852201 8.662807 yhatstar | 10000 1.449505 1.399097 3.29e-13 8.662807 . . * Do it "by hand" . gen sigma = _b[sigma:_cons] . gen myhatstar = normal(yhat/sigma)*(yhat+sigma* /// > normalden(-yhat/sigma)/normal(yhat/sigma)) . . * The wrong way of getting predictions . gen ystarwrong = max(0, yhat) . > . * Compare . sum y yhat yt yhatstar myhatstar ystarwrong Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- y | 10000 .9556056 2.225627 -7.519608 8.417286 yhat | 10000 .9682756 1.972654 -6.852201 8.662807 yt | 10000 1.452821 1.594159 0 8.417286 yhatstar | 10000 1.449505 1.399097 3.29e-13 8.662807 myhatstar | 10000 1.449505 1.399097 3.29e-13 8.662807 -------------+-------------------------------------------------------- ystarwrong | 10000 1.365353 1.457802 0 8.662807 . . log close name: log: U:\projects\misc\stata_lf_programs\tobit\tobit_expected_value.txt log type: text closed on: 31 Oct 2014, 13:25:58 ------------------------------------------------------------------------------------------