Saturday, May 12, 2012

Average Partial Effects




* Average Partial Effects (APEs)

* Stata Simulation to generate a binary response variables
* We want to estimate the average partial effect.
* Of the explanatory variable.  This often a more useful
* estimate than the coefficients from the probit.

* Set up the simulation
set seed 101
clear
set obs 10000

* Generate two explanatory variables
gen subsidy = rbinomial(1,.5)
  label define subsidy 0 "No Subsidy" 1 "Subsidy"
  label values subsidy subsidy
gen road_access = rbinomial(1,.3)
  label define road_access 0 "No Road Access" 1 "Road Access"
  label values road_access road_access

* Generate the error terms
gen u=rnormal()*5

* Generate the linear form that will be normally transformed
gen XB_u= 2*subsidy + road_access + u

sum XB_u

gen XB_u_norm = (XB_u-r(mean))/r(sd)
gen double Py=normal(XB_u_norm)
label var Py "True probability of market sale"
gen y=rbinomial(1,Py)

* We have to first calculate the true average partial effect.
* Since it is not possible to specify it ex ante directly through
* the simulation proceedure.

* Generate y with subsidy = 0
gen XB_X10_u= 2*0 + road_access + u

* Calculate the probability of 1 with subsidy == 0
sum XB_u
gen XB_subsidy0_u_norm = (XB_X10_u-r(mean))/r(sd)

* Calculate the average partial effect of subsidy
gen double Py_subsidy0=normal(XB_subsidy0_u_norm)

* Generate partial effect.
gen double pe_subsidy0=(Py-Py_subsidy0)/subsidy

* Generate y with road_access size = 0
gen XB_RA0_u= 2*subsidy +1*0 + u

sum XB_u
gen XB_RA0_u_norm = (XB_RA0_u-r(mean))/r(sd)

* Calculate the average partial effect of subsidy
gen double Py_RA0=normal(XB_RA0_u_norm)

* Calculate the average partial effect
* road_access size.
gen double pe_RA=(Py-Py_RA0)/road_access

sum pe*

************************************************************************
* Simulation END

probit y subsidy road_access

margins, dydx(*)
* This command finds the average partial effect of the explanatory variable on the
* the probability observing a 1 in the dependent variable.  This is basically taking
* the partial effects estimated by the probit for each observation then taking the
* average across all observations.

* This is extremely useful because the direct results of the probit estimations
* can not be directly interpreted as partial effects without a transformation.

reg y subsidy road_access
* Interestingly, the OLS model ignoring the binary nature of the response variable
* yields results that are very similar to the post estimation partial effects estimates.

predict u_hat, residual
graph box u_hat, over(subsidy) over(road_access) ///
  title(Residuals by Road access and Subsidy) legend(on)
* We can see that the errors are heteroskedastic in the explanatory variables.

* We we use heteroskedastically robust standard errors since by necessity
* the errors are heteroskedastic.
reg y subsidy road_access, robust

sum pe*
* We can see the results of the previous estimations are pretty good at estimating
* the true partial effects.

No comments :

Post a Comment