version 8.0 log using cox.log, replace #delimit ; * ***************************************************************** *; * ***************************************************************** *; * File-Name: cox.do *; * Date: 4/15/06 *; * Author: MRG *; * Purpose: PA Article using Amorim Neto and Cox 1997 data *; * Input File: coxappend.dta *; * Output File: cox.log *; * Data Output: coxappend.dta *; * Previous file: *; * Machine: *; * **************************************************************** *; * **************************************************************** *; set mem 10m use "coxappend.dta", clear * **************************************************************** *; * Summary Statistics *; * **************************************************************** *; sum * **************************************************************** *; * Dichotomize the Data *; * **************************************************************** *; gen multiparty=. replace multiparty=1 if enps>2.99 replace multiparty=0 if enps<3 gen multimember=. replace multimember=1 if ml>1 replace multimember=0 if ml==1 tab multiparty multimember * **************************************************************** *; * Dichotomize eneth 1>median, 0 otherwise. *; * **************************************************************** *; sum eneth, detail gen heterogeneity=. replace heterogeneity=1 if eneth>1.2775 replace heterogeneity=0 if eneth<1.2775 * **************************************************************** *; * Graph of legislative parties against ln(magnitude). *; * **************************************************************** *; graph twoway scatter enps lnml, mlabel(var12) mlabsize(2) msize(1) xlabel(0 1 2 3 4 5 6, labsize(2.5)) ylabel(1 3 5 7 9, labsize(2.5)) title("Figure 3: The Relationship between Electoral Laws and Party System Size", size(4)) xtitle(Log of Median District Magnitude, size(3)) ytitle(Effective Number of Legislative Parties, size(3)) yline(1 3 5 7 9, lcolor(white)) scheme(s2mono) graphregion(fcolor(white)) * **************************************************************** *; * Get standard deviations around mean of legislative parties in *; * single member and multi-member districts. *; * **************************************************************** *; sum enps if multi==1 sum enps if multi==0 * **************************************************************** *; * Run regression for results with dichotomous variables. *; * **************************************************************** *; gen multi_heterogeneity = multimember*heterogeneity regress enps heterogeneity multimember multi_heterogeneity * **************************************************************** *; * Predicted number of parties - homogenous and single-member *; * **************************************************************** *; lincom 1*_cons * **************************************************************** *; * Predicted number of parties - heterogeneous and single-member *; * **************************************************************** *; lincom 1*_cons + 1*heterogeneity * **************************************************************** *; * Predicted number of parties - homongeous and multi-member *; * **************************************************************** *; lincom 1*_cons + 1* multimember * **************************************************************** *; * Predicted number of parties - heterogeneous and multi-member *; * **************************************************************** *; lincom 1*_cons + 1* multimember +1*heterogeneity + 1*multi_heterogeneity * **************************************************************** *; * Calculate marginal effects with dichotomous variables *; * **************************************************************** *; regress enps heterogeneity multimember multi_heterogeneity lincom 1*heterogeneity lincom 1*heterogeneity + 1*multi_heterogeneity, level(94) ********************************************************************************************************************** Using Stata's Margins and Marginsplot ********************************************************************************************************************** regress enps c.eneth##c.lnml * The overall margin—the margin that holds nothing constant. margins * Average marginal effects margins, dydx(*) * Now, let's try to examine conditional marginal effects in a manner analogous to what we will do below with Brambor Clark and Golder. margins, dydx(eneth) at(lnml=(0 1 2 3 4 5)) * Note that marginsplot is less helpful as it does not tell us the statistical significance as does margins. marginsplot * Now let's examine dydx of lnml at different values of eneth margins, dydx(lnml) at(eneth=(1 2 3 4 )) * **************************************************************** *; * Run regression for results with continuous variables. *; * **************************************************************** *; * Case 1 regress enps eneth lnml lmleneth **************************************************************************************************** * Use the margins command to evaluate the predicted effects and write up your own do file. **************************************************************************************************** * The code between the lines of stars below come from a set of programs that Guy Whitten has prepared based on some code originally * provided by Brambor et al. * In order to use these code, we need only to do the following: * 1) set up the model in the following order: Model Y = f(X Z XZ Controls) * where Y is the dependent variable, X is independent variable for which we wish to look at the estimated * effect, Z is the independent variable across which we will look at the effect of X on Y and XZ is * the interaction between these two terms. In the model that we just estimated above, * Y=enps * X=eneth * Z=lnml * XZ=lmleneth * NOTE: The order of the model matters here because the code below are written to grab particular elements * from the variance-covariance matrix of the last model estimated. The code will only work if * the model is specified in the proper order. * 2) Change the fourth line under the row of stars to indicate which variable is the Z variable. In this * case it is lnml. In this code "MV" is short for "Marginal Variable" which is the variable that * will define the horizontal axis in our graph. ***************************************************************************************************** * Here is where you set the MV equal to the Z variable: generate MV=lnml matrix b=e(b) matrix V=e(V) scalar b1=b[1,1] scalar b2=b[1,2] scalar b3=b[1,3] scalar varb1=V[1,1] scalar varb2=V[2,2] scalar varb3=V[3,3] scalar covb1b3=V[1,3] scalar covb2b3=V[2,3] scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3 * This calculates the marginal effect of X on Y: gen conb=b1+b3*MV * This calculates the standard error of the estimate of the effect that we just calculated: gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) * This generates the upper and lower bounds although these should be modified according to the * number of degrees of freedom if you do not have as many as we have in this model: gen a=1.96*conse gen upperl=conb+a gen lowerl=conb-a * Now for the graph: sort MV graph twoway rarea upperl lowerl MV /* */ || line conb MV /* */ || , /* */ legend(col(1) order(1 2) label(1 "95% Confidence Interval") /* */ label(2 "Marginal Effect of ENETH")) /* */ yline(0, lcolor(black)) /* */ title("Marginal Effect of ENETH on ENPS As LNML Changes") /* */ subtitle(" " "Dependent Variable: ENPS" " ", size(3)) /* */ xtitle(LNML) /* */ ytitle("Marginal Effect of ENETH", size(3)) * Here is another version of the same graph, but in black and white. This would probably * be a more appropriate version for journal submission sort MV graph twoway line conb MV, clwidth(medium) clcolor(blue) clcolor(black) /* */ || line upperl MV, clpattern(dash) clwidth(thin) clcolor(black) /* */ || line lower MV, clpattern(dash) clwidth(thin) clcolor(black) /* */ || , /* */ legend(col(1) order(1 2) label(1 "Marginal Effect of X") /* */ label(2 "95% Confidence Interval") /* */ label(3 " ")) /* */ yline(0, lcolor(black)) /* */ title("Marginal Effect of X on Y As Z Changes", size(4)) /* */ subtitle(" " "Dependent Variable: Y" " ", size(3)) /* */ xtitle( Z, size(3) ) /* */ xsca(titlegap(2)) /* */ ysca(titlegap(2)) /* */ ytitle("Marginal Effect of X", size(3)) /* */ scheme(s2mono) graphregion(fcolor(white)) * This last line drops all of the variables that were constructed for this graph so that these code * can be copied and pasted and used again without problems. drop MV conb conse a upperl lower *****************************************************************************************************