Sie sind auf Seite 1von 5

HOWCANICOMPAREREGRESSION

COEFFICIENTSACROSS3(ORMORE)GROUPS?|
STATAFAQ
Sometimesyourresearchmaypredictthatthesizeofaregressioncoefficientmayvaryacross
groups.Forexample,youmightbelievethattheregressioncoefficient
ofheightpredictingweightwoulddifferacross3agegroups(young,middleage,seniorcitizen).
Below,wehaveadatafilewith10fictionalyoungpeople,10fictionalmiddleagepeople,and10
fictionalseniorcitizens,alongwiththeirheightininchesandtheirweightinpounds.The
variableageindicatestheagegroupandiscoded1foryoungpeople,2formiddleaged,and3for
seniorcitizens.

idageheightweight
1156140
2160155
3164143
4168161
5172139
6154159
7162138
8165121
9165161
10170145
11256117
12260125
13264133
14268141
15272149
16254109
17262128
18265131
19265131
20270145
21364211
22368223
23372235
24376247
25380259
26362201
27369228
28374245
29375241
30382269

Weanalyzetheirdataseparatelyusingtheregresscommandbelowafterfirstsortingbyage.

usehttp://www.ats.ucla.edu/stat/stata/faq/compreg3,clear

sortage
byage:regressweightheight
Theparameterestimates(coefficients)fortheyoung,middleage,andseniorcitizensareshown
below,andtheresultsdoseemtosuggestthatheightisastrongerpredictorofweightforseniors
(3.18)thanforthemiddleaged(2.09).Theresultsalsoseemtosuggestthatheightdoesnot
predictweightasstronglyfortheyoung(.37)asforthemiddleagedandseniors.However,we
wouldneedtoperformspecificsignificanceteststobeabletomakeclaimsaboutthedifferences
amongtheseregressioncoefficients.

>age=1

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
height|.3768309.77433410.4870.6402.1624491.408787
_cons|170.166449.430183.4430.00956.18024284.1526

>age=2

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
height|2.095872.11049118.9690.0001.841082.350665
_cons|2.397477.0532720.3400.74318.6623413.8674

>age=3

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
height|3.189727.123236725.8830.0002.9055433.473912
_cons|5.6016778.9301970.6270.54814.9913926.19475

Wecancomparetheregressioncoefficientsamongthesethreeagegroupstotestthenull
hypothesis

Ho:B1=B2=B3

whereB1istheregressionfortheyoung,B2istheregressionforthemiddleaged,andB3isthe
regressionforseniorcitizens.Todothisanalysis,wefirstmakeadummyvariablecalledage1thatis
coded1ifyoung(age=1),0otherwise,andage2thatiscoded1ifmiddleaged(age=2),0otherwise.
Wealsocreateage1htthatisage1timesheight,andage2htthatisage2timesheight.

generateage1=0
generateage2=0
replaceage1=1ifage==1
replaceage2=1ifage==2
generateage1ht=age1*height
generateage2ht=age2*height

Wecannowuseage1age2height,age1htandage2htaspredictorsintheregressionequationin
theregresscommandbelow.Theregresscommandwillbefollowedbythecommand:
testage1htage2ht

whichteststhenullhypothesis:

Ho:B1=B2=B3

Thistestwillhave2dfbecauseitcomparesthreeregressioncoefficients.

regressweightage1age2heightage1htage2ht
Source|SSdfMSNumberofobs=30
+F(5,24)=220.26
Model|69595.3546513919.0709Prob>F=0.0000
Residual|1516.645362463.1935565Rsquared=0.9787
+AdjRsquared=0.9742
Total|71112.00292452.13793RootMSE=7.9494

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
age1|164.564841.55493.9600.00178.79966250.3299
age2|7.99914741.55490.1920.84993.7642577.76596
height|3.189727.40694177.8380.0002.3498414.029614
age1ht|3.566558.61316095.8170.0004.832062.301057
age2ht|1.093855.61316091.7840.0872.359357.1716466
_cons|5.60167729.488540.1900.85155.2596766.46303

Theanalysisbelowshowsthatthenullhypothesis

Ho:B1=B2=B3

canberejected(F=17.29,p=0.0000).Thismeansthattheregressioncoefficients
betweenheightandweightdoindeedsignificantlydifferacrossthe3agegroups(young,middle
age,seniorcitizen).

testage1htage2ht

(1)age1ht=0.0
(2)age2ht=0.0
F(2,24)=17.29
Prob>F=0.0000

Notethatweconstructedallofthevariablesmanuallytomakeitveryclearwhateachvariable
represented.However,indaytodayuse,youwouldprobablybemorelikelytousethexiprefixto
generatethedummyvariablesandinteractionsforyou.Forexample,
regressweighti.age##c.height

Source|SSdfMSNumberofobs=30
+F(5,24)=220.26
Model|69595.3546513919.0709Prob>F=0.0000
Residual|1516.645362463.1935565Rsquared=0.9787
+AdjRsquared=0.9742
Total|71112292452.13793RootMSE=7.9494

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
age|
2|172.563941.406194.170.000258.022187.10574
3|164.564841.55493.960.001250.329978.79966
|
height|.3768309.45865530.820.4191.323449.5697872
|
age#c.height|
2|2.472703.64863663.810.0011.1339833.811423
3|3.566558.61316095.820.0002.3010564.83206
|
_cons|170.166429.27865.810.000109.7384230.5945

However,youmayseethatinthisexamplethefirstagegroupistheomittedgroup,wherepreviously
thethirdgroupwastheomittedgroup.Wecansetthebase(orreference)group3byspecifyingb3
aftertheiinthefactorvariablenotation.(Thebisforbase.)

regressweightib3.age##c.height
Source|SSdfMSNumberofobs=30
+F(5,24)=220.26
Model|69595.3546513919.0709Prob>F=0.0000
Residual|1516.645362463.1935565Rsquared=0.9787
+AdjRsquared=0.9742
Total|71112292452.13793RootMSE=7.9494

weight|Coef.Std.Err.tP>|t|[95%Conf.Interval]
+
age|
1|164.564841.55493.960.00178.79966250.3299
2|7.99914741.55490.190.84993.7642577.76596
|
height|3.189727.40694177.840.0002.3498414.029614
|
age#c.height|
1|3.566558.61316095.820.0004.832062.301056
2|1.093855.61316091.780.0872.359357.1716466
|
_cons|5.60167729.488540.190.85155.2596766.46303

Das könnte Ihnen auch gefallen