* ***************************************************************** *
* ***************************************************************** *
* File-Name: Tobit E(y).do *
* Date: October 13, 2011 *
* Author: Travis Braidwood, Florida State University *
* tbraidwood@fsu.edu *
* Purpose: Generating predicted probability/expected value *
* graphs for use with Tobit model specifications *
* Input File: n/a.dta, data is STATA generated *
* Data Output: None *
* Prev. file: None *
* Accompanying file: n/a *
* Machine: Home *
* **************************************************************** *
* **************************************************************** *
********************************************************************************
/*
A note to users: Tobit offers several specifications (See Cameron and Trivedi
2005; Breen 1996). This .do file addresses one of those specifications: the
expected value of Y: E[Y] (Breen 1996). The equations offered may be used
regardless of the censor point, however for truncated data users should
consult the aforementioned econometric resources, or another of their choosing.
*/
********************************************************************************
clear all
set seed 0210
set obs 1000
set scheme s1mono
set more off, perm
version 11
*
gen y = rnormal(5)*.25
gen x1 = runiform()*.25
gen x2 = runiform()*-2
gen x3 = runiform()*2.5
sum
replace y=0 if y<=1
/* we've purposefully censored some data at 0, let's assume it could
actually be negative */
*
*Now let's compair regression to tobit (this Tobit gives us E(y*|x), which = x'B)
reg y x1 x2 x3
tobit y x1 x2 x3, ll(0)
preserve //preserve variables so we can restore later
*
*Let's draw some simulated coeffs from the tobit model (above)
drawnorm tb1-tb5, n(10000) means(e(b)) cov(e(V)) clear
/* note that above you will need to change the number of "tb" variables produced
depending on the number of independent variables in your model. "tb" will need
to equal n+2, where n is the number of independent variables. Example: here
there are (n=3)+2=5*/
save simulated_betas, replace
restore
merge using simulated_betas
drop _merge
*
/* Now need to set the values we are interested in. Here we want to know x2
from min to max*/
*
local a = -1.996294 //the min
scalar x1 = .1258682 //mean
scalar x3 = 1.254568 //mean
scalar constant = 1
*
/* now let's calculate E[y], expected unconditional value of the variable.
Note, if the censor point is 0, as it is here, the latter half of the equation
at the end of the equation simply drops away */
postutil clear
postfile mypost Ey upper lower using simresults, replace
noisily display "start"
set obs 10000
while `a' <= -.0047823 /* which is the max for x2 */ {
qui gen xb = tb1*x1 + tb2*`a' + tb3*x3 + tb4*constant
qui gen s = tb5 //sigma
qui gen c = 0 //the censoring point
qui gen invmills = normalden(xb/s)/normal(xb/s) //inverse mills ratio
qui gen d = (xb-c)/s //not used here, but will be in other tobit specifications
qui gen Ey = (normal(xb/s))*(xb+(s*invmills))+(1-normal(xb/s))*c //our predicted value
_pctile Ey, p(2.5,97.5) //now 95% confidence intervals
scalar upper = r(r1)
scalar lower = r(r2)
post mypost (Ey) (upper) (lower)
local a = `a'+.05 // the amount we will increase x2 by
drop xb s c invmills d Ey //drop all values so we can begin the loop again
display "." _c
}
display ""
*
postclose mypost
use simresults, clear
*
sum
gen MV = (_n-1)
gsort Ey upper lower -MV
*
graph twoway line Ey MV, clwidth(medium) clcolor(navy) clpattern(solid) ///
|| line lower MV, clpattern(dash) clwidth(thin) clcolor(maroon) ///
|| line upper MV, clpattern(dash) clwidth(thin) clcolor(maroon) ///
ytitle(Y-Axis Label) xtitle(X-Axis Label)