Anda di halaman 1dari 8

Dummy Variabel

Kasus 1: Dummy dan Interaksi Dummy


1. Gunakan data dummy1.dta!
Deskripsi data:

Salary: (average) salary of public school teacher in state i


Spending: = spending on public school per pupil ($)
State: negara bagian (W, N, S)
2. Buatlah deskripsi data salary dan spending
3. Dengan model regresi carilah rata-rata salary untuk masing-masing negara!
4. Buatlah model berikut dan lakukan analisis:
= +
+
+
D2

= 1 if the state is in the Northeast or North Central (N)


= 0 otherwise (i.e., in other region of the country)

5. Buatlah model untuk mengetahui apakah ada perbedaan pengaruh spending terhadap salary
antar state dan lakukan analisis!
JAWAB

Jawab 2

. desc

storage display
value
variable name
type
format
label
variable label
---------------------------------------------------------------------------------------------------------------------salary
float %9.0g
spending
int
%8.0g
d2
byte
%8.0g
d3
byte
%8.0g
state
str1
%9s
d1
float %9.0g
statecode
float %9.0g
---------------------------------------------------------------------------------------------------------------------Sorted by:
Note: dataset has changed since last saved
. sum

salary spending

Variable |
Obs
Mean
Std. Dev.
Min
Max
-------------+-------------------------------------------------------salary |
51
24356.22
4179.426
18095
41480
spending |
51
3696.608
1054.761
2297
8349

Jawab 3

. regress salary d1 d2 d3, noconstant

Source |
SS
df
MS
-------------+-----------------------------Model | 3.0333e+10
3 1.0111e+10
Residual |
794703718
48 16556327.5
-------------+-----------------------------Total | 3.1128e+10
51
610350346

Number of obs
F( 3,
48)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

51
610.71
0.0000
0.9745
0.9729
4068.9

Number of obs
F( 2,
48)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

51
2.38
0.1038
0.0901
0.0522
4068.9

Number of obs
F( 2,
48)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

51
59.41
0.0000
0.7122
0.7003
2288.2

-----------------------------------------------------------------------------salary |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------d1 |
26158.62
1128.523
23.18
0.000
23889.57
28427.66
d2 |
24424.14
887.917
27.51
0.000
22638.87
26209.42
d3 |
22894
986.8645
23.20
0.000
20909.78
24878.22
------------------------------------------------------------------------------

Atau
. regress salary d2 d3

Source |
SS
df
MS
-------------+-----------------------------Model |
78676547
2 39338273.5
Residual |
794703718
48 16556327.5
-------------+-----------------------------Total |
873380265
50 17467605.3

-----------------------------------------------------------------------------salary |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------d2 | -1734.473
1435.953
-1.21
0.233
-4621.649
1152.704
d3 | -3264.615
1499.155
-2.18
0.034
-6278.868
-250.3625
_cons |
26158.62
1128.523
23.18
0.000
23889.57
28427.66
------------------------------------------------------------------------------

Jawab 4

reg

salary i.d2

spending

Source |
SS
df
MS
-------------+-----------------------------Model |
622063283
2
311031642
Residual |
251316981
48 5235770.44
-------------+-----------------------------Total |
873380265
50 17467605.3

-----------------------------------------------------------------------------salary |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------1.d2 | -1059.971
659.9094
-1.61
0.115
-2386.807
266.8661
spending |
3.389222
.3109787
10.90
0.000
2.763958
4.014487
_cons |
12264.05
1181.48
10.38
0.000
9888.523
14639.57
-----------------------------------------------------------------------------. margins

d2, at ( spending=(2297 8349)) vsquish

Adjusted predictions
Model VCE
: OLS
Expression
1._at
2._at

: Linear prediction, predict()


: spending
=
2297
: spending
=
8349

Number of obs

51

-----------------------------------------------------------------------------|
Delta-method
|
Margin
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------_at#d2 |
1 0 |
20049.09
572.0839
35.05
0.000
18927.83
21170.36
1 1 |
18989.12
705.7021
26.91
0.000
17605.97
20372.27
2 0 |
40560.67
1548.618
26.19
0.000
37525.43
43595.9
2 1 |
39500.7
1470.709
26.86
0.000
36618.16
42383.23
-----------------------------------------------------------------------------. marginsplot

Adjusted Predictions of d2 with 95% CIs

20000

Linear Prediction
30000
40000

50000

Variables that uniquely identify margins: spending d2

2297

spending

d2=0

8349
d2=1

Jawab 5
. reg

salary i.statecode##c.spending

Source |
SS
df
MS
-------------+-----------------------------Model |
640881764
5
128176353
Residual |
232498501
45 5166633.35
-------------+-----------------------------Total |
873380265
50 17467605.3

Number of obs
F( 5,
45)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

51
24.81
0.0000
0.7338
0.7042
2273

-------------------------------------------------------------------------------------salary |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
---------------------+---------------------------------------------------------------statecode |
1 | -3950.555
3090.229
-1.28
0.208
-10174.6
2273.485
2 | -5040.081
3075.927
-1.64
0.108
-11235.32
1155.154
|
spending |
2.9428
.4205673
7.00
0.000
2.095734
3.789866
|

statecode#c.spending |
1 |
.5821196
.7639819
0.76
0.450
-.956619
2.120858
2 |
1.121671
.860531
1.30
0.199
-.6115274
2.854869
|
_cons |
14625.33
1764.716
8.29
0.000
11071.01
18179.65
-------------------------------------------------------------------------------------. margins

statecode, at ( spending=(2297 8349))

Adjusted predictions
Model VCE
: OLS
Expression

: Linear prediction, predict()

2._at

: spending

1._at

: spending

=
=

Number of obs

51

2297
8349

------------------------------------------------------------------------------|
Delta-method
|
Margin
Std. Err.
z
P>|z|
[95% Conf. Interval]
--------------+---------------------------------------------------------------_at#statecode |
1 0 |
21384.94
928.9048
23.02
0.000
19564.32
23205.56
1 1 |
18771.51
1136.72
16.51
0.000
16543.58
20999.44
1 2 |
18921.34
917.813
20.62
0.000
17122.46
20720.22
2 0 |
39194.77
1966.821
19.93
0.000
35339.87
43049.67
2 1 |
40104.33
2880.218
13.92
0.000
34459.21
45749.45
2 2 |
43519.52
3849.465
11.31
0.000
35974.71
51064.33
------------------------------------------------------------------------------. marginsplot

Variables that uniquely identify margins: spending statecode

50000
20000

Linear Prediction
30000
40000

Adjusted Predictions of statecode with 95% CIs

2297

spending

statecode=0
statecode=2

Kasus 2: Piecewise Linear Regression

8349
statecode=1

1. Gunakan data piecewise_reg.dta!


2. Buatlah scatter plot untuk antara output (sebagai independent var) dan totalcost (sebagai
dependent variable) untuk menunjukkan apakah ada hubungan linier antara independent var
dan depependent var!
3. Buatlah model yang digunakan untuk menentukan apakah ada perbedaan totalcost setelah
output melewati treshold (threshold=5500)!
4. Seandainya ada perbedaan yang signifikan antara totalcost sebelum dan setelah output
threshold, bagaimana persamaan totalcost pada kedua kondisi tersebut?
5. Buatlah grafiknya prediksinya!

Jawab 2

. twoway (scatter totalcost output)

3000
2000
totalcost
1000
0

2000

4000

output

6000

8000

10000

Jawab 3 dan 4

. gen D= output>5500

. gen output_1=output-5500

. gen output_1_D= output_1* D


. reg

totalcost output output_1_D

Source |
SS
df
MS
-------------+-----------------------------Model |
8832644.9
2 4416322.45
Residual | 238521.502
7 34074.5002
-------------+-----------------------------Total |
9071166.4
9 1007907.38

Number of obs
F( 2,
7)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

10
129.61
0.0000
0.9737
0.9662
184.59

-----------------------------------------------------------------------------totalcost |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------output |
.2791258
.0460081
6.07
0.001
.1703338
.3879177
output_1_D |
.0945
.0825524
1.14
0.290
-.1007054
.2897054
_cons | -145.7167
176.7341
-0.82
0.437
-563.6265
272.1932
------------------------------------------------------------------------------

Jawab 5
. mkspline out1 5500 out2= output
. showcoding output out1 out2
+----------------------+

| output
out1
out2 |
|----------------------|
|
1000
1000
0 |
|
2000
2000
0 |
|
3000
3000
0 |
|
4000
4000
0 |
|
5000
5000
0 |
|
6000
5500
500 |
|
7000
5500
1500 |
|
8000
5500
2500 |
|
9000
5500
3500 |
| 10000
5500
4500 |
+----------------------+

Linear prediction
1000
2000

3000

. reg totalcost out1 out2


. predict tc_hat, xb
. graph twoway line tc_hat output, xlabel(0(1000)10000) xline(5500)

Tambahan
. lincom

1000

2000

out2 - out1

3000

4000

5000 6000
output

7000

8000

9000 10000

3000
2000
1000
0

2000

4000
totalcost

output

6000
Fitted values

8000

10000