87K - views

Title stata

com margins contrast Contrasts of margins Syntax Menu Description Suboptions Remarks and examples Stored results Methods and formulas Reference Also see Syntax margins marginlist if in weight contr ast ma

Embed :
Pdf Download Link

Download Pdf - The PPT/PDF document "Title stata" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Title stata






Presentation on theme: "Title stata"— Presentation transcript:

2margins,contrast—Contrastsofmargins MenuStatistics�Postestimation�ContrastsofmarginsDescriptionmarginswiththecontrastoptionorwithcontrastoperatorsperformscontrastsofmargins.Thisextendsthecapabilitiesofcontrasttoanyofthenonlinearresponses,predictivemargins,orothermarginsthatcanbeestimatedbymargins.Suboptions  � Contrast �overallspeciesthatajointhypothesistestoveralltermsbeperformed.lincomspeciesthatuser-denedcontrastsbetreatedaslinearcombinations.Thedefaultistorequirethatalluser-denedcontrastssumtozero.(Summingtozeroispartofthedenitionofacontrast.)atcontrast(op. at)speciesthattheop.contrastoperatorbeappliedtothegroupsdenedbytheat()option(s).Thedefaultbehavior,bycomparison,istoperformtestsandcontrastswithinthegroupsdenedbytheat()option(s).Seeexample6inRemarksandexamples.atjointspeciesthatjointtestsbeperformedacrossallgroupsdenedbytheat()option.Thedefaultbehavior,bycomparison,istoperformcontrastsandtestswithineachgroup.Seeexample5inRemarksandexamples.overjointspecieshowunoperatedvariablesintheover()optionaretreated.Eachvariableintheover()optionmaybespeciedeitherwithorwithoutacontrastoperator.Forcontrast-operatedvariables,thespeciedcontrastcomparisonsarealwaysperformed.overjointspeciesthatjointtestsbeperformedacrossalllevelsoftheunoperatedvariables.Thedefaultbehavior,bycomparison,istoperformcontrastsandtestswithineachcombinationoflevelsoftheunoperatedvariables.Seeexample3inRemarksandexamples.withinjointspecieshowunoperatedvariablesinthewithin()optionaretreated.Eachvariableinthewithin()optionmaybespeciedeitherwithorwithoutacontrastoperator.Forcontrast-operatedvariables,thespeciedcontrastcomparisonsarealwaysperformed.withinjointspeciesthatjointtestsbeperformedacrossalllevelsoftheunoperatedvariables.Thedefaultbehavior,bycomparison,istoperformcontrastsandtestswithineachcombinationoflevelsoftheunoperatedvariables.marginswithinspecieshowunoperatedvariablesinmarginlistaretreated.Eachvariableinmarginlistmaybespeciedeitherwithorwithoutacontrastoperator.Forcontrast-operatedvariables,thespeciedcontrastcomparisonsarealwaysperformed.marginswithinspeciesthatcontrastsandtestsbeperformedwithineachcombinationoflevelsoftheunoperatedvariables.Thedefaultbehavior,bycomparison,istoperformjointtestsacrossalllevelsoftheunoperatedvariables.Seeexample4inRemarksandexamples. margins,contrast—Contrastsofmargins5 Eachchi-squaredstatisticisajointtestofconstituentcontrasts.Thetestforgrouphastwodegreesoffreedombecausegrouphasthreelevels. Contrastsandtheover()option Example2Itiscommontoestimatemarginsatcombinationsoffactorlevels,andmargins,contrastincludesseveralsuboptionsforcontrastingsuchmargins.Let'stamodelwithtwocategoricalpredictorsandtheirinteraction:.logisticoutcomeagegroup##groupLogisticregressionNumberofobs=3000LRchi2(8)=520.64Prob�chi2=0.0000Loglikelihood=-1105.7504PseudoR2=0.1906 outcome OddsRatioStd.Err.z�P|z|[95%Conf.Interval] agegroup 30-39 3.541912.2269512.010.0441.03288212.1457640+ 16.233519.611884.710.0005.08645251.80955 group 2 .834507.5663738-0.270.790.22066113.155983 .2146729.1772897-1.860.062.04254071.083303 agegroup# group 30-39#2 .4426927.3358505-1.070.283.10007721.95825730-39#3 1.1608851.1035270.160.875.18015437.48055340+#2 .440672.3049393-1.180.236.11352591.7105540+#3 .4407912.4034688-0.890.371.07332.650709 _cons .0379747.0223371-5.560.000.0119897.1202762 Eachofagegroupandgrouphasthreelevels.Tocompareeachagegroupwiththereferencecategoryontheprobabilityscale,wecanagainusemarginswithther.contrastoperator. 6margins,contrast—Contrastsofmargins .marginsr.agegroupContrastsofpredictivemarginsModelVCE:OIMExpression:Pr(outcome),predict() dfchi2�Pchi2 agegroup (30-39vs20-29) 110.040.0015(40+vs20-29) 1224.440.0000Joint 2238.210.0000 Delta-method ContrastStd.Err.[95%Conf.Interval] agegroup (30-39vs20-29) .044498.0140448.0169706.0720253(40+vs20-29) .2059281.0137455.1789874.2328688 Ourmodelincludesaninteraction,though,soitwouldbenicetoestimatethecontrastsseparatelyforeachvalueofgroup.Weneedtheover()option:.marginsr.agegroup,over(group)ContrastsofpredictivemarginsModelVCE:OIMExpression:Pr(outcome),predict()over:group dfchi2�Pchi2 agegroup@group (30-39vs20-29)1 16.940.0084(30-39vs20-29)2 11.180.2783(30-39vs20-29)3 13.100.0783(40+vs20-29)1 1173.420.0000(40+vs20-29)2 157.770.0000(40+vs20-29)3 15.120.0236Joint 6266.840.0000 Delta-method ContrastStd.Err.[95%Conf.Interval] agegroup@group (30-39vs20-29)1 .0819713.0311208.0209757.142967(30-39vs20-29)2 .0166206.0153309-.0134275.0466686(30-39vs20-29)3 .0243462.0138291-.0027583.0514508(40+vs20-29)1 .3447797.0261811.2934658.3960937(40+vs20-29)2 .1540882.0202722.1143554.193821(40+vs20-29)3 .0470319.0207774.006309.0877548 Theeffectofagegroupappearstobegreatestfortherstlevelofgroup.Includingavariableintheover()optionisnotequivalenttoincludingthevariableinthemainmarginlist.Thevariablesinthemarginlistaremanipulatedintheanalysis,sothatwecanmeasure,forexample,theeffectofbeinginagegroup3andnotagegroup1.(Themanipulationcouldbemimickedbyrunningreplaceandthenpredict,butthemanipulationsactuallyperformedbymarginsdonot 8margins,contrast—Contrastsofmargins Thecontrast(overjoint)optionoverridesthedefaultbehaviorofover()andrequestsjointtestsoverthelevelsoftheunoperatedvariablegroup.Thechi-squaredstatisticof3.62teststhattherstandthirdcontrastsfromtheprevioustablearejointlyzero.Thechi-squaredstatisticof79.45jointlyteststheotherpairofcontrasts. Themarginswithinsuboption Example4Anothersuboptionthatmayusefullybecombinedwithover()ismarginswithin.margins-withinrequeststhatcontrastsbeperformedwithinthelevelsofunoperatedvariablesinthemainmarginlist,insteadofperformingthemjointlyacrossthelevels.marginswithinaffectsonlyunop-eratedvariablesbecausecontrastoperatorstakeprecedenceoversuboptions.Let'srstlookatthedefaultbehavior,whichoccurswhenmarginswithinisnotspecied:.marginsagegroup,over(r.group)contrast(effects)ContrastsofpredictivemarginsModelVCE:OIMExpression:Pr(outcome),predict()over:group dfchi2�Pchi2 group#agegroup (2vs1)(joint) 233.940.0000(3vs1)(joint) 283.380.0000Joint 483.880.0000 Delta-method ContrastStd.Err.z�P|z|[95%Conf.Interval] group# agegroup (2vs1) (30-39 vs base) -.0653508.0346921-1.880.060-.133346.0026445(2vs1) (40+ vs base) -.1906915.0331121-5.760.000-.25559-.1257931(3vs1) (30-39 vs base) -.0576251.0340551-1.690.091-.1243719.0091216(3vs1) (40+ vs base) -.2977479.0334237-8.910.000-.3632572-.2322385 Hereagegroupinthemainmarginlistisanunoperatedvariable,somarginsbydefaultperformsjointtestsacrossthelevelsofagegroup:thechi-squaredstatisticof33.94,forexample,jointlytestswhetherthersttwocontrastestimatesinthelowertablediffersignicantlyfromzero. 10margins,contrast—Contrastsofmargins .marginsr.agegroup,at(group=(1/3))ContrastsofadjustedpredictionsModelVCE:OIMExpression:Pr(outcome),predict()1._at:group=12._at:group=23._at:group=3 dfchi2�Pchi2 agegroup@_at (30-39vs20-29)1 16.940.0084(30-39vs20-29)2 11.180.2783(30-39vs20-29)3 13.100.0783(40+vs20-29)1 1173.420.0000(40+vs20-29)2 157.770.0000(40+vs20-29)3 15.120.0236Joint 6266.840.0000 Delta-method ContrastStd.Err.[95%Conf.Interval] agegroup@_at (30-39vs20-29)1 .0819713.0311208.0209757.142967(30-39vs20-29)2 .0166206.0153309-.0134275.0466686(30-39vs20-29)3 .0243462.0138291-.0027583.0514508(40+vs20-29)1 .3447797.0261811.2934658.3960937(40+vs20-29)2 .1540882.0202722.1143554.193821(40+vs20-29)3 .0470319.0207774.006309.0877548 Ouroptionat(group=(1/3))manipulatesthevaluesofgroupandisthereforenotequivalenttoover(group).Weseethatthereference-categorycontrastsforagegrouphavebeenperformedwithineachat()level.Forasimilarexamplethatusesthe. atoperatorinsteadoftheat()option,seeContrastsofat()groups—discreteeffectsin[R]marginsplot.Thedefaultwithinbehaviorofat()maybechangedtojointbehaviorwiththeatjointsuboption:.marginsr.agegroup,at(group=(1/3))contrast(atjoint)ContrastsofadjustedpredictionsModelVCE:OIMExpression:Pr(outcome),predict()1._at:group=12._at:group=23._at:group=3 dfchi2�Pchi2 _at#agegroup (joint)(30-39vs20-29) 23.620.1641(joint)(40+vs20-29) 279.450.0000Joint 483.880.0000 Nowthetestsareperformedjointlyoverthelevelsofgroup,theat()variable.Theatjointsuboptionistheanalogueforat()oftheoverjointsuboptionfromexample3. margins,contrast—Contrastsofmargins13 Toseehowunionstatusaffectswages,wecanusemargins:.marginsr.union,vce(unconditional)ContrastsofpredictivemarginsExpression:Predictednumberofevents,predict() dfchi2�Pchi2 union 126.220.0000 Unconditional ContrastStd.Err.[95%Conf.Interval] union (unionvsnonunion) 1.004119.1960944.61978151.388457 Theestimatedcontrast1.004indicatesthatonaverage,belongingtoaunioncausesawoman'swagetobeslightlymorethanadollarhigherthanifshewerenotintheunion.Thisestimatedcontrastiscalledtheaveragetreatmenteffect(ATE).Conceptually,wepredictedthewageofeachwomanintheestimationsampleassumingshewasinaunionandobtainedthesamplemean.Wethenpredictedeachwoman'swageassumingshewasnotinaunionandobtainedthatsamplemean.ThedifferencebetweenthesetwosamplemeansrepresentstheATE.Weobtainessentiallythesameresultsbyusingteffectsra:.teffectsra(wagec.gradec.ttl_exp##c.ttl_exp,poisson)(union)Iteration0:EEcriterion=2.611e-13Iteration1:EEcriterion=1.098e-26Treatment-effectsestimationNumberofobs=1876Estimator:regressionadjustmentOutcomemodel:PoissonTreatmentmodel:none Robustwage Coef.Std.Err.z�P|z|[95%Conf.Interval] ATE union (union vs nonunion) 1.004119.19604215.120.000.6198841.388355 POmean union nonunion 7.346493.109618267.020.0007.1316457.561341 ThepointestimatesoftheATEareidenticaltothoseweobtainedusingmargins,thoughthestandarderrorsdifferslightlyfromthosereportedbymargins.Thestandarderrorsfromthetwoestimatorsare,however,asymptoticallyequivalent,meaningtheywouldcoincidewithasufcientlylargedataset.Thelaststatisticinthisoutputtableindicatestheuntreatedpotential-outcomemean(untreatedPOM),whichisthemeanpredictedwageassumingeachwomandidnotbelongtoaunion.Ifwespecifythepomeansoptionwithteffectsra,wecanobtainboththetreatedandtheuntreatedPOMs,whichrepresentthepredictedmeanwagesassumingallwomenwereorwerenotintheunion: margins,contrast—Contrastsofmargins15 Toreplicatetheseresultsusingteffectsra,weincludetheatetoptiontoobtainATETs:.teffectsra(wagec.gradec.ttl_exp##c.ttl_exp,poisson)(union),atetIteration0:EEcriterion=2.611e-13Iteration1:EEcriterion=9.324e-27Treatment-effectsestimationNumberofobs=1876Estimator:regressionadjustmentOutcomemodel:PoissonTreatmentmodel:none Robustwage Coef.Std.Err.z�P|z|[95%Conf.Interval] ATET union (union vs nonunion) .901419.20753094.340.000.49466581.308172 POmean union nonunion 7.776417.16212147.970.0007.4586658.094168 Weobtainthesamepointestimateoftheeffectofunionstatusaswithmargins.Asbefore,thestandarderrorsdifferslightlybetweenthetwoestimators,buttheyareasymptoticallyequivalent.Theoutputalsoindicatesthatamongthewomenwhoareinaunion,theiraveragewagewouldbe$7.78iftheywerenotinaunion. TechnicalnoteOneadvantageoftheATETovertheATEisthattheATETcanbeconsistentlyestimatedwithslightlyweakerassumptionsthanarerequiredtoconsistentlyestimatetheATE.SeeComparingtheATEandATETinRemarksandexamplesof[TE]teffectsintroadvanced. Bothmarginsandteffectscanestimatetreatmenteffectsusingregressionadjustment,sowhichshouldyouuse?Inadditiontoregressionadjustment,theteffectscommandimplementsotherestimatorsoftreatmenteffects;someoftheseestimatorspossessdesirablerobustnesspropertiesthatwecannotreplicateusingmargins.Moreover,alltheteffectsestimatorsuseacommonsyntaxandautomaticallypresenttheestimatedtreatmenteffects,whereaswemustrsttourownregressionmodelandthencallmarginstoobtainthetreatmenteffects.Ontheotherhand,particularlywiththeat()option,marginsgivesusmoreexibilityinspecifyingourscenarios.Theteffectscommandsallowustomeasuretheeffectofasinglebinaryormultinomialtreatment,butwecanhavemarginscomputetheeffectsofarbitraryinterventions,asweillustrateinthenextexample. Example9:InterventionsinvolvingmultiplevariablesSupposewewanttoseehowwomen'swageswouldbeaffectedifwecouldincreaseeachwoman'seducationlevelbyoneyear.Thatis,wewanttomeasurethetreatmenteffectofanadditionalyearofschooling.Weassumethatifawomanattainsanotheryearofschooling,shecannotsimultaneouslywork.Thusanadditionalyearofeducationimplieshertotalworkexperiencemustdecreasebyayear.Theexibleat()optionofmarginsallowsustomanipulatebothvariablesatonce: 16margins,contrast—Contrastsofmargins .quietlypoissonwagei.union##(c.gradec.ttl_exp##c.ttl_exp),vce(robust).margins,at((asobserved)_all)�at(grade=generate(grade+1)ttl_exp=generate(ttl_exp-1))�contrast(atcontrast(r._at))ContrastsofpredictivemarginsModelVCE:RobustExpression:Predictednumberofevents,predict()1._at:(asobserved)2._at:grade=grade+1ttl_exp=ttl_exp-1 dfchi2�Pchi2 _at 158.530.0000 Delta-method ContrastStd.Err.[95%Conf.Interval] _at (2vs1) .3390392.0443161.2521813.4258971 Therstat()optioninstructsmarginstoobtainpredictedwagesforallwomeninthesampleusingtheirexistingvaluesforgradeandttl expandtorecordthemeanofthosepredictions.Thesecondat()optioninstructsmarginstoobtainthemeanpredictedwageunderthecounterfactualscenariowhereeachwoman'seducationlevelisincreasedbyoneyearandtotalworkexperienceissimultaneouslydecreasedbyoneyear.Thecontrast()optioninstructsmarginstocomputethedifferencebetweenthetwomeans.Theoutputindicatesthatincreasingeducationbyoneyear,whichwillnecessarilydecreaseworkexperiencebythesameamount,willcausetheaveragewagetoincreasebyabout34centsperhour,astatisticallysignicantamount. Conclusionmargins,contrastisapowerfulcommand,anditsabundanceofsuboptionsmayseemdaunting.Thesuboptionsareintheserviceofonlythreegoals,however.Therearethreethingsthatmargins,contrastcandowithafactorvariableorasetofat()denitions:1.Performcontrastsacrossthelevelsofthefactororset(asinexample1).2.Performajointtestacrossthelevelsofthefactororset(asinexample5).3.Performothertestsandcontrastswithineachlevelofthefactororset(asinexample4).Thedefaultbehaviorforvariablesspeciedinsideat(),over(),andwithin()istoperformcontrastswithingroups;thedefaultbehaviorforvariablesinthemarginlististoperformjointtestsacrossgroups.