**************************************************** * This Stata .do file provides code to replicate * * all tables (except 10-12) in * * Kam, Cindy D. & Robert J. Franzese, Jr. * * (2007) * * Modeling and Interpreting Interactive Hypotheses * * in Regression Analysis * * Ann Arbor, MI: University of Michigan Press. * **************************************************** *This file is written for Stata/SE v9.2 for Windows* * but should be compatible with other versions * *******************DATASETS************************************** *We use four datasets in our text: *1. "candidates" * Cox's Presidential Candidates dataset * Original data source: http://dodgson.ucsd.edu/lij/pubs/ *2. "socialwelfare" * Support for Social Welfare * Original data source: NES 2004 *3. "govduration" * Government Duration * Original data source: collected by Franzese *4. "turnout" * Voter turnout * Original data source: NES 2004 /*Each of these datasets is available for download separately or in the zip file.*/ /*Place the datasets in one folder. */ /*Change the directory below following the "cd" command to customize to your directory.*/ /*The example below refers to a folder on the C: drive called "MIH".*/ cd "C:\MIH" log using all_tables, replace /*creates a log file with .smcl extension*/ ****************************************************************** *****************************TABLES******************************* ****************************************************************** *TABLE 1: OLS REGRESSION RESULTS, NUMBER OF PRESIDENTIAL CANDIDATES use candidates, clear gen groupsrunoff= groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" est store table1 est table table1, b(%9.3f) se p(%9.3f) stats(N r2) *TABLE 2: PREDICTED NUMBER OF PRESIDENTIAL CANDIDATES clear set obs 5 egen groups= fill(1(.5)3) expand 2 gen runoff= . replace runoff= 0 in 1/5 replace runoff= 1 in 6/10 gen groupsrunoff= groups*runoff gen col1=1 save candidates_yhat.dta, replace use candidates.dta gen groupsrunoff= groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" use candidates_yhat.dta, clear mkmat groups runoff groupsrunoff col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) tabdisp groups runoff, cellvar(Yhat) f(%9.3f) /*A shorthand way, using the canned postestimation command, predict*/ predict yhat tabdisp groups runoff, cellvar(yhat) f(%9.3f) *TABLE 3: OLS REGRESSION RESULTS, SUPPORT FOR SOCIAL WELFARE use socialwelfare, clear gen femRep = female*Republican regress socwel female Republican femRep est store table3 est table table3, b(%9.4f) se p(%9.3f) stats(N r2) *TABLE 4: PREDICTED SUPPORT FOR SOCIAL WELFARE clear set obs 2 gen female = _n-1 gen Republican = 0 expand 2 replace Republican = 1 in 3/4 gen femRep= female*Republican gen col1=1 save socialwelfare_yhat.dta, replace use socialwelfare.dta gen femRep = female*Republican regress socwel female Republican femRep use socialwelfare_yhat.dta, clear mkmat female Republican femRep col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) tabdisp female Republican, cellvar(Yhat) f(%9.3f) /*A shorthand way, using the canned postestimation command, predict*/ predict yhat tabdisp female Republican, cellvar(yhat) f(%9.3f) *TABLE 5: OLS REGRESSION RESULTS, GOVERNMENT DURATION: SIMPLE LINEAR-INTERACTION MODEL use govduration, clear gen NPPS = NP*PS reg govdur NP PS NPPS PD est store table5 est table table5, b(%9.3f) se p(%9.3f) stats(N r2) *TABLE 6: PREDICTED GOVERNMENT DURATION clear set obs 5 egen PS= fill(40(10)80) gen NP = 1 gen PD = 1 gen col1=1 expand 2 replace NP = 2 in 6/10 expand 2 replace NP = 3 in 11/15 replace NP = 4 in 16/20 gen NPPS = NP*PS save govduration_yhat.dta, replace use govduration, clear gen NPPS = NP*PS reg govdur NP PS NPPS PD use govduration_yhat.dta, clear mkmat NP PS NPPS PD col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) tabdisp PS NP, cellvar(Yhat) f(%9.2f) /*A shorthand way, using the canned postestimation command, predict*/ predict yhat tabdisp PS NP, cellvar(yhat) f(%9.2f) *TABLE 7: OLS REGRESSION RESULTS, GOVERNMENT DURATION: QUADRATIC-TERM MODEL use govduration, clear gen PS_sq = PS*PS reg govdur PS PS_sq est store table7 est table table7, b(%9.3f) se p(%9.3f) stats(N r2) *TABLE 8: OLS REGRESSION RESULTS, GOVERNMENT DURATION: LOG-TRANSFORMATION INTERACTIVE MODEL use govduration, clear gen lnPS = ln(PS) gen NPlnPS = NP*lnPS reg govdur NP lnPS NPlnPS PD est store table8 est table table8, b(%9.3f) se p(%9.3f) stats(N r2) *TABLE 9: OLS REGRESSION RESULTS, GOVERNMENT DURATION: THREE-WAY INTERACTIVE MODELS use govduration, clear gen NPPS = NP*PS gen NPPD = NP*PD gen PDPS = PD*PS gen NPPSPD = NP*PS*PD reg govdur NP PS PD NPPS NPPD est store chained reg govdur NP PS PD NPPS NPPD PDPS est store pairwise reg govdur NP PS PD NPPS NPPD PDPS NPPSPD est store fully est table chained pairwise fully, b(%9.3f) se p(%9.3f) *TABLES 10-12 ARE THEORETICAL; NO DATA ANALYSIS *TABLE 13: ESTIMATED VARIANCE COVARIANCE MATRIX OF COEFFICIENT ESTIMATES *IN MODEL PREDICTING NUMBER OF PRESIDENTIAL CANDIDATES use candidates, clear gen groupsrunoff= groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" vce, f(%9.3f) *TABLE 14: HYPOTHESIS TESTS OF WHETHER GROUPS AFFECTS NUMBER OF PRESIDENTIAL CANDIDATES clear set obs 5 egen groups = fill(1(.5)3) gen runoff = 0 expand 2 replace runoff = 1 in 6/10 save dcandidatesdx.dta, replace use candidates, clear gen groupsrunoff= groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" use dcandidatesdx.dta, clear gen dydG = _b[groups]+_b[groupsrunoff]*runoff /*Calculates the marginal effect of Groups*/ matrix V = get(VCE) /*Assigns matrix name V to the estimated var-cov matrix*/ gen C_G_GR = V[3,1] /*Pulls out the exact covariance we want from V by its location*/ gen vardydG = (_se[groups]^2)+runoff*runoff*(_se[groupsrunoff]^2)+2*runoff*C_G_GR /*Generates the variance around the marginal effect*/ gen sedydG = sqrt(vardydG) /*Standard error is the square root of variance*/ gen tstatdydG = dydG/sedydG /*t-statistic is marginal effect over its standard error*/ /*Testing against the null hypothesis dydG<=0*/ gen dydGless = ttail(e(df_r),tstatdydG) /*Testing against the null hypothesis dydG>=0*/ gen dydGmore = 1-ttail(e(df_r),(tstatdydG)) /*90% Confidence intervals*/ gen LBdydG = dydG-invttail(e(df_r),.05)*sedydG gen UBdydG = dydG+invttail(e(df_r),.05)*sedydG tabdisp runoff, cellvar(dydG sedydG tstatdydG dydGless dydGmore) f(%9.3f) tabdisp runoff, cellvar(LBdydG UBdydG) f(%9.3f) *TABLE 15: HYPOTHESIS TESTS OF WHETHER RUNOFF AFFECTS NUMBER OF PRESIDENTIAL CANDIDATES gen dydR = _b[runoff]+_b[groupsrunoff]*groups matrix V = get(VCE) gen C_R_GR = V[3,2] gen vardydR = (_se[runoff]^2)+groups*groups*(_se[groupsrunoff]^2)+2*groups*C_R_GR gen sedydR = sqrt(vardydR) gen tstatdydR = dydR/sedydR /*Testing against the null hypothesis dydR<=0*/ gen dydRless = ttail(e(df_r),tstatdydR) /*Testing against the null hypothesis dydR>=0*/ gen dydRmore = 1-ttail(e(df_r),tstatdydR) /*90% Confidence intervals*/ gen LBdydR = dydR-invttail(e(df_r),.05)*sedydR gen UBdydR = dydR+invttail(e(df_r),.05)*sedydR tabdisp groups, cellvar(dydR sedydR tstatdydR dydRless dydRmore) f(%9.3f) tabdisp groups, cellvar(LBdydR UBdydR) f(%9.3f) *TABLE 16: ESTIMATED VARIANCE-COVARIANCE MATRIX OF COEFFICIENT ESTIMATES, PREDICTING use socialwelfare, clear gen femRep = female*Republican regress socwel female Republican femRep vce, f(%9.5f) *TABLE 17: HYPOTHESIS TESTS OF WHETHER FEMALE AFFECTS SUPPORT FOR SOCIAL WELFARE clear set obs 2 gen female = _n-1 gen Republican = 0 expand 2 replace Republican = 1 in 3/4 gen femRep= female*Republican gen col1=1 save dsocweldx.dta, replace use socialwelfare, clear gen femRep = female*Republican regress socwel female Republican femRep use dsocweldx.dta, clear gen dydF = _b[female]+_b[femRep]*Republican matrix V = get(VCE) gen C_F_FR = V[3,1] gen vardydF = (_se[female]^2)+Republican*Republican*(_se[femRep]^2)+2*Republican*C_F_FR gen sedydF = sqrt(vardydF) gen tstatdydF = dydF/sedydF /*Testing against the null hypothesis dydF<=0*/ gen dydFless = ttail(e(df_r),tstatdydF) /*Testing against the null hypothesis dydF>=0*/ gen dydFmore = 1-ttail(e(df_r),(tstatdydF)) /*95% Confidence intervals*/ gen LBdydF = dydF-invttail(e(df_r),.025)*sedydF gen UBdydF = dydF+invttail(e(df_r),.025)*sedydF tabdisp Republican, cellvar(dydF sedydF tstatdydF dydFless dydFmore) f(%9.4f) tabdisp Republican, cellvar(LBdydF UBdydF) f(%9.4f) *TABLE 18: HYPOTHESIS TESTS OF WHETHER REPUBLICAN AFFECTS SUPPORT FOR SOCIAL WELFARE gen dydR = _b[Republican]+_b[femRep]*female matrix V = get(VCE) gen C_R_FR = V[3,2] gen vardydR = (_se[Republican]^2)+female*female*(_se[femRep]^2)+2*female*C_R_FR gen sedydR = sqrt(vardydR) gen tstatdydR = dydR/sedydR /*Testing against the null hypothesis dydR<=0*/ gen dydRless = ttail(e(df_r),tstatdydR) /*Testing against the null hypothesis dydR>=0*/ gen dydRmore = 1-ttail(e(df_r),(tstatdydR)) /*95% Confidence intervals*/ gen LBdydR = dydR-invttail(e(df_r),.025)*sedydR gen UBdydR = dydR+invttail(e(df_r),.025)*sedydR tabdisp female, cellvar(dydR sedydR tstatdydR dydRless dydRmore) f(%9.4f) tabdisp female, cellvar(LBdydR UBdydR) f(%9.3f) *TABLE 19: ESTIMATED VARIANCE-COVARIANCE MATRIX OF COEFFICIENT ESTIMATES, PREDICTING GOVERNMENT DURATION use govduration, clear gen NPPS = NP*PS reg govdur NP PS NPPS PD vce, f(%9.3f) *TABLE 20: HYPOTHESIS TESTS OF WHETHER NUMBER OF PARTIES AFFECTS GOVERNMENT DURATION clear set obs 5 egen PS = fill(40(10)80) gen NP = 1 expand 2 replace NP = 2 in 6/10 expand 2 replace NP = 3 in 11/15 replace NP = 4 in 16/20 save dgovdurdx.dta, replace use govduration, clear gen NPPS = NP*PS reg govdur NP PS NPPS PD use dgovdurdx.dta, clear gen dydNP = _b[NP]+_b[NPPS]*PS matrix V = get(VCE) gen C_NP_NPPS= V[3,1] gen vardydNP = (_se[NP]^2)+PS*PS*(_se[NPPS]^2)+2*PS*C_NP_NPPS gen sedydNP = sqrt(vardydNP) gen tstatdydNP = dydNP/sedydNP /*Testing against the null hypothesis dydNP<=0*/ gen dydNPless = ttail(e(df_r),tstatdydNP) /*Testing against the null hypothesis dydNP>=0*/ gen dydNPmore = 1-ttail(e(df_r),(tstatdydNP)) /*90% Confidence intervals*/ gen LBdydNP = dydNP-invttail(e(df_r),.05)*sedydNP gen UBdydNP = dydNP+invttail(e(df_r),.05)*sedydNP tabdisp PS, cellvar(dydNP sedydNP tstatdydNP dydNPless dydNPmore) f(%9.3f) tabdisp PS, cellvar(LBdydNP UBdydNP) f(%9.3f) *TABLE 21: HYPOTHESIS TESTS OF WHETHER PARLIAMENTARY SUPPORT AFFECTS GOVERNMENT DURATION gen dydPS = _b[PS]+_b[NPPS]*NP matrix V = get(VCE) gen C_PS_NPPS= V[3,2] gen vardydPS = (_se[PS]^2)+NP*NP*(_se[NPPS]^2)+2*NP*C_PS_NPPS gen sedydPS = sqrt(vardydPS) gen tstatdydPS = dydPS/sedydPS /*Testing against the null hypothesis dydPS<=0*/ gen dydPSless = ttail(e(df_r),tstatdydPS) /*Testing against the null hypothesis dydPS>=0*/ gen dydPSmore = 1-ttail(e(df_r),(tstatdydPS)) /*90% Confidence intervals*/ gen LBdydPS = dydPS-invttail(e(df_r),.05)*sedydPS gen UBdydPS = dydPS+invttail(e(df_r),.05)*sedydPS tabdisp NP, cellvar(dydPS sedydPS tstatdydPS dydPSless dydPSmore) f(%9.3f) tabdisp NP, cellvar(LBdydPS UBdydPS) f(%9.3f) *TABLE 22: CONFIDENCE INTERVALS FOR PREDICTED NUMBER OF PRESIDENTIAL CANDIDATES use candidates, clear gen groupsrunoff=groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" use candidates_yhat.dta, clear mkmat groups runoff groupsrunoff col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) matrix V = get(VCE) matrix VCEYH=Mh*V*Mh' matrix VYH= (vecdiag(VCEYH))' svmat VYH, name(vyhat) gen seyhat = sqrt(vyhat) tabdisp groups, cellvar(Yhat seyhat) gen LByhat=Yhat-invttail(e(df_r),.05)*seyhat gen UByhat=Yhat+invttail(e(df_r),.05)*seyhat tabdisp groups if runoff==0, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) tabdisp groups if runoff==1, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) /*shortcut, using canned postestimation commands*/ predict yhat predict yhatse, stdp gen LB2 = yhat-invttail(e(df_r),.05)*yhatse gen UB2 = yhat+invttail(e(df_r),.05)*yhatse tabdisp groups if runoff==0, cellvar(yhat yhatse LB2 UB2) f(%9.3f) tabdisp groups if runoff==1, cellvar(yhat yhatse LB2 UB2) f(%9.3f) *TABLE 23: CONFIDENCE INTERVALS FOR PREDICTED SUPPORT FOR SOCIAL WELFARE use socialwelfare.dta, clear gen femRep = female*Republican regress socwel female Republican femRep use socialwelfare_yhat.dta, clear mkmat female Republican femRep col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) matrix V = get(VCE) matrix VCEYH=Mh*V*Mh' matrix VYH= (vecdiag(VCEYH))' svmat VYH, name(vyhat) gen seyhat = sqrt(vyhat) gen LByhat=Yhat-invttail(e(df_r),.025)*seyhat gen UByhat=Yhat+invttail(e(df_r),.025)*seyhat tabdisp female if Republican==0, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) tabdisp female if Republican==1, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) */A shorthand way, using the canned postestimation command, predict*/ predict yhat predict yhatse, stdp gen LB2 = yhat-invttail(e(df_r),.025)*yhatse gen UB2 = yhat+invttail(e(df_r),.025)*yhatse tabdisp female if Republican==0, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) tabdisp female if Republican==1, cellvar(Yhat seyhat LByhat UByhat) f(%9.3f) *TABLE 24: CONFIDENCE INTERVALS FOR PREDICTED GOVERNMENT DURATION use govduration, clear gen NPPS = NP*PS reg govdur NP PS NPPS PD use govduration_yhat.dta, clear mkmat NP PS NPPS PD col1, matrix(Mh) matrix B=e(b)' matrix Yhat=Mh*B svmat Yhat, name(Yhat) matrix V = get(VCE) matrix VCEYH=Mh*V*Mh' matrix VYH= (vecdiag(VCEYH))' svmat VYH, name(vyhat) gen seyhat = sqrt(vyhat) gen LByhat=Yhat-invttail(e(df_r),.05)*seyhat gen UByhat=Yhat+invttail(e(df_r),.05)*seyhat bysort NP: tabdisp PS, cellvar(Yhat seyhat LByhat UByhat) f(%9.2f) */A shorthand way, using the canned postestimation command, predict*/ predict yhat predict yhatse, stdp gen LB2 = yhat-invttail(e(df_r),.025)*yhatse gen UB2 = yhat+invttail(e(df_r),.025)*yhatse bysort NP: tabdisp PS, cellvar(Yhat seyhat LByhat UByhat) f(%9.2f) *TABLE 25: CONFIDENCE INTERVALS FOR DIFFERENCES IN PREDICTED NUMBER OF CANDIDATES *Use marginal effects, and multiply by change of 2 use candidates, clear gen groupsrunoff= groups*runoff reg candidates groups runoff groupsrunoff if country~="BOLIVIA" & country~="HONDURAS" & country~="URUGUAY" use dcandidatesdx.dta, clear gen dydG = _b[groups]+_b[groupsrunoff]*runoff gen CH_2_dydG = dydG*2 matrix V = get(VCE) gen C_G_GR = V[3,1] gen vardydG = (_se[groups]^2)+runoff*runoff*(_se[groupsrunoff]^2)+2*runoff*C_G_GR gen CH_2_vardydG = vardydG*2*2 gen sedydG = sqrt(vardydG) gen CH_2_sedydG = sqrt(CH_2_vardydG) /*90% Confidence intervals*/ gen LBdydG = dydG-invttail(e(df_r),.05)*sedydG gen CH_2_LBdydG = CH_2_dydG-invttail(e(df_r),.05)*CH_2_sedydG gen UBdydG = dydG+invttail(e(df_r),.05)*sedydG gen CH_2_UBdydG = CH_2_dydG+invttail(e(df_r),.05)*CH_2_sedydG tabdisp runoff, cellvar(dydG sedydG LBdydG UBdydG) f(%9.3f) tabdisp runoff, cellvar(CH_2_dydG CH_2_sedydG CH_2_LBdydG CH_2_UBdydG) f(%9.3f) *TABLE 26: OLS REGRESSION RESULTS, SUPPORT FOR SOCIAL WELFARE, POOLED AND SPLIT SAMPLES use socialwelfare, clear gen femRep = female*Republican regress socwel female Republican femRep est store pooled regress socwel Republican if female==0 est store males regress socwel Republican if female==1 est store females est table pooled males females, b(%9.4f) se p(%9.3f) stats(N r2) *TABLE 27: LOGIT AND PROBIT REGRESSION RESULTS, TURNOUT use turnout, clear gen yrschlstr = yrschl*strpid logit vote04 yrschl strpid yrschlstr est store logit probit vote04 yrschl strpid yrschlstr est store probit est table logit probit, b(%9.3f) se p(%9.3f) stats(N ll) *TABLE 28: MARGINAL EFECTS OF SCHOOLING, USING LOGIT RESULTS clear set obs 3 gen yrschl = (_n+2)*3 gen strpid = 0 gen col1=1 expand 2 replace strpid = 1 in 4/6 expand 2 replace strpid = 2 in 7/9 replace strpid = 3 in 10/12 gen yrschlstr=yrschl*strpid save dturnoutdx, replace use turnout, clear gen yrschlstr = yrschl*strpid logit vote04 yrschl strpid yrschlstr use dturnoutdx, clear predict phat gen dpdyrschl= phat*(1-phat)*(_b[yrschl]+_b[yrschlstr]*strpid) tabdisp yrschl strpid, cellvar(dpdyrschl) f(%9.3f) *********STANDARD ERRORS AROUND MARGINAL EFFECTS FOR LOGIT********* /*Looking at the formula for s.e. around the marginal effects, pages 120-121*/ /* ((phat)*(1-phat))^2 * [r'Vr + 2*s_L*x'Vr + s_L^2*x'Vx] */ /*First term inside the big parenthetical expression: r'Vr */ /*The vector "r" represents multipliers for the marginal effects, page 120*/ /*The text notes that r' = [1 0 z 0] in our case*/ /*The first cell maps onto the b for yrschl */ /*The second cell maps onto the b for strpid */ /*The third cell maps onto the b for the yrschl*strpid interaction*/ /*The fourth cell represents the constant*/ /*Since we want dp/dyrschl, the value of third cell varies with level of strpid*/ matrix r_0 = (1\0\0\0) /*when strpid is held to 0, r_0 is the multiplier*/ matrix r_1 = (1\0\1\0) /*when strpid is held to 1, r_1 is the multiplier*/ matrix r_2 = (1\0\2\0) matrix r_3 = (1\0\3\0) /*We could multiply each r vector separately, but it's more expedient to stack them into a matrix*/ gen col0 = 0 mkmat col1 col0 strpid col0, matrix(R) matlist R /*each r' appears as a row in the matrix R */ /*We can now create the first term, r'Vr in the big parenthetical in the text*/ matrix V=get(VCE) matrix A1 = R*V*R' matrix A1diags = vecdiag(A1)' svmat A1diags, name(A1) /*A1 is a variable that takes on distinct values by strength of partisanship*/ tab A1 strpid /*Now, let's create the second term, 2*s_L*x'Vr*/ /*s_L is a multiplier based on the p-hat and a couple other things that we can put together*/ gen s_L=(1-2*phat)*(_b[yrschl]+_b[yrschlstr]*strpid) /*The vector x' refers the values at which our X's are set*/ /*So, make a matrix based on all of the X's*/ mkmat yrschl strpid yrschlstr col1, matrix(Mh) matlist Mh /*This matrix contains all the set values that we will examine*/ /*each x' appears as a row in the matrix Mh */ /*Now, just multiply x'Vr together, using the appropriate r vector*/ /*Take care to use the appropriate r vector to postmultiply by the appropriate x line */ /*To do so, use the matrix R created above*/ matrix A2 = Mh*V*R' matrix A2diags = vecdiag(A2)' svmat A2diags, name(A2) /*A2 is a variable that takes on distinct values by strength of partisanship AND years of schooling*/ tab A2 strpid tab A2 yrschl /*Now, let's create the third term, s_L^2*x'Vx */ matrix A3 = Mh*V*Mh' matrix A3diags= vecdiag(A3)' svmat A3diags, name(A3) tab A31 gen vardpdyrschl= (phat*(1-phat))^2*(A1+2*s_L*A2+s_L*s_L*A3) gen sedpdyrschl= sqrt(vardpdyrschl) tabdisp yrschl strpid, cellvar(dpdyrschl sedpdyrschl) f(%9.3f) *TABLE 29: MARGINAL EFECTS OF STRENGTH OF PARTISANSHIP, USING LOGIT RESULTS use turnout, clear gen yrschlstr = yrschl*strpid logit vote04 yrschl strpid yrschlstr use dturnoutdx, clear predict phat gen dpdstrpid= phat*(1-phat)*(_b[strpid]+_b[yrschlstr]*yrschl) tabdisp yrschl strpid, cellvar(dpdstrpid) f(%9.3f) *********STANDARD ERRORS AROUND MARGINAL EFFECTS FOR LOGIT********* /*Looking at the formula for s.e. around the marginal effects, pages 120-121*/ /* ((phat)*(1-phat))^2 * [r'Vr + 2*s_L*x'Vr + s_L^2*x'Vx] */ /*First term inside the big parenthetical expression: r'Vr */ /*The vector "r" represents multipliers for the marginal effects, page 120*/ /*Now r' = [0 1 x 0] now that we are using our other variable, strpid*/ /*The first cell maps onto the b for yrschl */ /*The second cell maps onto the b for strpid */ /*The third cell maps onto the b for the yrschl*strpid interaction*/ /*The fourth cell represents the constant*/ /*Since we want dp/dstrpid, the value of third cell varies with years of schooling*/ matrix r_9 = (0\1\9\0) /*when yrschl is held to 9, r_9 is the multiplier*/ matrix r_12 = (0\1\12\0) matrix r_15 = (0\1\15\0) /*Combining these into one matrix*/ gen col0 = 0 mkmat col0 col1 yrschl col0, matrix(R) /*We can now create the first term, r'Vr in the big parenthetical in the text*/ matrix V=get(VCE) matrix A1 = R*V*R' matrix A1diag = vecdiag(A1)' svmat A1diag, name(A1) /*A1 is a variable that takes on distinct values by years of schooling*/ tab A1 yrschl /*Now, let's create the second term, 2*s_L*x'Vr*/ /*s_L is a multiplier based on the p-hat and a couple other things that we can put together*/ gen s_L=(1-2*phat)*(_b[strpid]+_b[yrschlstr]*yrschl) /*The vector x' refers the values at which our X's are set*/ /*So, make a matrix based on all of the X's*/ mkmat yrschl strpid yrschlstr col1, matrix(Mh) matlist Mh /*This matrix contains all the set values that we will examine*/ /*each x' appears as a row in the matrix Mh */ /*Now, just multiply x'Vr together, using the appropriate r vector*/ /*Take care to use the appropriate r vector to postmultiply by the appropriate x line */ /*To do so, use the same matrix R above*/ matrix A2 = Mh*V*R' matrix A2diags = vecdiag(A2)' svmat A2diags, name(A2) /*A2 is a variable that takes on distinct values by strength of partisanship AND years of schooling*/ tab A2 strpid tab A2 yrschl /*Now, let's create the third term, s_L^2*x'Vx */ matrix A3 = Mh*V*Mh' matrix A3diags= vecdiag(A3)' svmat A3diags, name(A3) tab A31 gen vardpdstrpid= (phat*(1-phat))^2*(A1+2*s_L*A2+s_L*s_L*A3) gen sedpdstrpid= sqrt(vardpdstrpid) tabdisp yrschl strpid, cellvar(dpdstrpid sedpdstrpid) f(%9.3f) **************END FILE*************** *****LAST MODIFIED JUNE 15, 2007*****