175
Econommetric Part 2 Dr.Woraphon Yamaka

Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EconommetricPart 2

Dr.Woraphon Yamaka

Page 2: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Chapter 1Regression with Time-Series Data: Stationary Variables

Dr. Woraphon Yamakahttps://wyamaka.wordpress.com

Page 3: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

1. Regression model

เพอใชศกษาผลกระทบของสงหนงตออกสงหนง ตวอยางเชน

Microeconomic: : Demand and supply equationsMacroeconomic Production function Cost function

EX. Demand equation

푌 = 푋 훽 + 휀

Qd P

Page 4: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

2.1 Dynamic regression model (Autoregressive (AR model)• คอการศกษาปจจยของตวมนเองในอดตสงผลตอตวมนเองในปจจบนอยางไร เราจะเขยน

แบบจาลอง AR(p)

• หรอเราจะเขยนในสมการอยางยอไดวา

1 1Q Qd dt t t tP

. 1 . 1 ...t t p t p tY Y Y

. .1

P

t p t p tp

Y Y

EX. Demand equation

ปกตแลวเราจะใชแบบจาลองนเพอการพยากรณคาในอนาคต

Page 5: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

2.2 Dynamic regression model (Moving Average (MA) model)• แบบจาลองนคลายๆกบ AR model แตแทนทจะทจะตวแปรตามจะเปน 푌 . แบบจาลองนจะทาการ

ถดถอยดวย 휀 แทน ดงนนสมการทเราทาการประมาณ MA(q) คอ

• หรอเราจะเขยนในสมการอยางยอไดวา. 1 . 1 ...t t q t q tY

.1

Q

t q t q tq

Y

ปกตแลวเราจะใชแบบจาลองนเพอการพยากรณคาในอนาคตเชนกน

Page 6: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

2.3 Dynamic regression model (Autoregressive Moving Average (ARMA) model)• แบบจาลองนคลายๆกบ AR model แตจะเพมพจน MA ขนมาในแบบจาลองดวย หรอกคอ

แบบจาลองนรวมแบบจาลอง AR และ แบบจาลอง MA เขาดวยกนนนเอง ดงนนแบบจาลอง ARMA(p,q) เขยนไดดงน

• หรอเราจะเขยนในสมการอยางยอไดวา

. 1 . 1 1 . 1... ...t t p t p t q t q tY Y Y

. .1 1

QP

t p t p q t q tp q

Y Y

แบบจาลองอน ๆทใชพยากรณในอนาคต เชน แบบจาลอง ARIMA, SARIMA และ AFRIMA

Page 7: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

สงแรกทตองคานงถงเกยวกบการประมาณดวยแบบจาลองเศรษฐมตตาง ๆ คออะไร

• คาตอบ

นกเศรษฐมตตองคานงถงหวขอวจยเปนอนดบแรก และสงทสาคญทสดรองลงมาคอความนาเชอถอของขอมล ซงในทางสถตหรอทางเศรษฐมตเราสามารถทาการเชคความนาเชอถอขอมล จากการทดสอบความนงของขอมล ซงเราจะตองทาการทดสอบขอมลกอนการประมาณแบบจาลองทางเศรษฐมต โดยเฉพาะแบบจาลองทเปน time series และ Panel.

ความนงของขอมลถอวาเปนอกสมมตฐานหนงทเราตองเพมขนมาอกขอตอจาก Gauss Markov Theorem

Page 8: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Stationary dataขอมลทนงคออะไร? -2

-10

12

x

02

46

812

0 20 40 60 80 100

yTime

ขอมลทมลกษณะทนงคอขอมลทคณสมบต คอ มคาเฉลย คาความ

แปรปรวน ทนงนนเอง

Page 9: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การทดสอบความนง หรอ Unit root test

• ในการทดสอบความนงของขอมล time series และ Panel จะมความแตกตางกนอยบาง โดยปจจบนสถตทใชของแตละขอมลกมหลากหลายวธดวยกน แตทเปนทนยมกนมาก กคอ

• Dickey Fuller (DF) test ( Time series data)• Augmented Dickey Fuller (ADF) test (Time series data)• Phillips perron test (PP) test (Time series data)• Kwiatkowski–Phillips–Schmidt–Shin (KPSS) test (Time series data)• Levin, Lin, and Chu (LLC) test ( Panel data)

ซงการทดสอบขอมลเหลาน จะใชสมการของแบบจาลอง dynamic regression มาประยกตใชในการทดสอบ

Page 10: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

DICKEY–FULLER TEST

1t t ty y u

1t t ty y u

1t t ty y t u

ในการทดสอบแบบ DF test เราสามารถทาได 3 วธดวยกน คอ

กรณไมมคาคงทและคาแนวโนม

กรณมคาคงทและไมมคาแนวโนมเวลา

กรณมคาคงทและมคาแนวโนมเวลา

โดยท 훥푦 = 푦 - 푦 푡 = 1,2,3,…,T

Page 11: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การทดสอบภายใต DICKEY–FULLER TEST

• ในกรณเราจะดวา คา 훾 =0 หรอไม ดงนนเราจะตงสมมตฐานไดวา

• จากการทดสอบขางตนเราจะเหนวาเปนการทดสอบตวแปรเดยว ดงนนเราสามารถใช T-test ในการทดสอบวาเราจะยอมรบหรอปฎเสธ 퐻

• สรปคอ ถา ยอมรบ –> ขอมลไมนง

ถา ปฎเสธ –> ขอมลนง

จากสมการทง 3 สมการขางตน เราควรทาการทดสอบทง 3 สมการเลย และดวาใหผลทางเดยวกนหรอไม

0

1

: 0 (nonstationary): 0 (stationary)

HH

Page 12: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การทดสอบภายใต Augmented DICKEY–FULLER TEST

• อยางไรกตามการทอสอบความนงของขอมลดวยวธ DF test ถกมองวายงมปญหาอย เนองจากอาจเกดปญหา autocorrelation และนาไปส OLS ไม BLUE ได และทาใหเกด Bias ขนในการประมาณ ดงนน เราจงตองระมดระวงปญหานในแบบจาลอง AR ดวย

• Augmented DICKEY–FULLER TEST จงถกพฒนาขนมา โดยปรบใหสมการ

11

P

t t p t p tp

y y y u

11

P

t t p t p tp

y y y u

11

P

t t p t p tp

y y y t u

กรณไมมคาคงทและคาแนวโนม

กรณมคาคงทและไมมคาแนวโนมเวลา

กรณมคาคงทและมคาแนวโนมเวลา

Page 13: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ปญหาทจะเกดในขอมล time series และ Panel ซงจะคลายๆ กบ Heteroscedasticity คอ

เปนปญหาทตวแปรรบกวนมความสมพนธกบตวมนเองในอดตนนเอง 푢 สมพนธกบ 푢 ซงกรณนเราจะ

เรยกวา First order autocorrelation

ปญหา Autocorrelation (คราวๆ)

v

Page 14: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบจาลอง Regression ทจาเปนตองมขอมลทนง

• แบบจาลองทางเศรษฐมตเกอบทกแบบจาลองทใชขอมลแบบ Time series และ Panel จะตองมการทดสอบความนงของขอมลกอนทจะนาไปประมาณผลการศกษา ถาขอมลนงเรากสามารถใชขอมลนนไปประมาณในแบบจาลองตอไปได แตถาขอมลไมนง เราตองมการแปลงขอมลใหนงกอนทจะไปใชในแบบจาลอง

• การแปลงขอมลสามารถทาไดหลายวธดวยกน เชน

• 1) ln(푦 )• 2) ln(푦 )- ln(푦 )• 3) 훥 (푦 )

Page 15: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Program training

• R code• Eview

Page 16: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code Unit root test (ADF-test)gnp=scan(file="http://faculty.chicagobooth.edu/ruey.tsay/teaching/fts3/dgnp82.txt")# To create a time-series objectgnp1=ts(gnp,frequency=4,start=c(1947,2))

par(mfrow=c(1,1))plot(gnp1)

points(gnp1,pch="*")# Use Package urcalibrary(urca)ur.df(gnp,type="none",lags=1)ur.df(gnp,type="drift",lags=1)ur.df(gnp,type="trend",lags=1)

Page 17: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code แบบจาลอง AR, MA และ ARMA # Find the AR orderm1=ar(gnp,method="mle")m1$order

m2=arima(gnp,order=c(3,0,0))summary(m2)

Page 18: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs Unit root test (1)

Page 19: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs Unit root test (2)

Double click

Page 20: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs Unit root test

View

Page 21: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs Unit root test

ตรงนคอใหเราเลอกวาจะเชค Unit root test แบบใด

Page 22: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs Unit root test ผลการศกษา

P value

ขอบเขตวกฤต

Page 23: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs AR model

Page 24: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs MA model

พมพ code คาสง ในตวอยางนคอ AR(1) หรอ 푌 = 훼 + 훽푌 + 푢

Page 25: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs AR model ผลการศกษา

Page 26: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs MA model

พมพ code คาสง ในตวอยางนคอ MA(1) หรอ 푌 = 훼 + 훾휇 + 휇

Page 27: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs MA model ผลการศกษา

Page 28: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs ARMA model

พมพ code คาสง ในตวอยางนคอ ARMA(1,1) หรอ

푌 = 훼 + 훽푌 + 훾휇 + 휇

Page 29: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

EVIEWs ARMA model ผลการศกษา

Page 30: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบฝกหด1) Dynamic regression และ regression เหมอนหรอตางกนอยางไร และจงยกตวอยางหวขอวจยทใช

แบบจาลอง Dynamic regression และ regression2) ปญหาความไมนงของขอมล เปนปญหาทผวจยตองคานงถงเมอใชขอมล cross section และ Time series ใช

หรอไม และเหตใดเราจงจาเปนตองตรวจสอบความนงของขอมล กอนการประมาณแบบจาลอง

3) จากขอมล GNP ทใชเปนตวอยางในบทน อยากใหทดสอบตวามนงของขอมลในทกรปแบบ โดยใชวธการทดสอบ ADF test และ Phillipis-Perron test และแสดงผลการศกษาในตารางใหพอเขาใจ (ดตวอยางจากบทความวจยในอดตวาแสดงผลการศกษาอยางไร ) พรอมทงแปลผลการศกษา

4) ในการพยากรณ GNP เราจะใชแบบจาลองรปแบบใด เปนแบบจาลองในการพยากรณอนาคต

Page 31: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Chapter 2Regression with Time-Series Data: Nonstationary Variables

Dr. Woraphon Yamakahttps://wyamaka.wordpress.com

Page 32: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Spurious Regression (การถดถอยทไมแทจรง)

• ปญหานจะทาใหแบบจาลองเศรษฐมตโดยเฉพาะแบบจาลองทใชขอมล Time series และ Panel เกดการถดถอยไมแทจรง กลาวคอเราไดผลการศกษาทมระดบนยสาคญ ทงทมนไมควรจะมนยสาคญขนจรง เชน เราทาการหาผลกระทบของการเจรญเตบโตของเสนผลตอการเปลยนแปลงของ GDP และเมอเราประมาณแบบจาลองไปเราอาจพบวาการเจรญเตบโตของเสนสงผลตอการเปลยนแปลงของ GDP ซงในทางทฤษฎแลวสองตวแปรนไมนาสมพนธกน การเกดผลการประมาณแบบนแสดงวาแบบจาลองทเราทาการประมาณอาจเกดปญหา Spurious นนเอง

• สาเหตหลกททาใหเกดปญหาคอ ตวแปรขอมลทเราใชในแบบจาลองไมมลกษณะนงนนเอง หรอขอมลทเราเกบมาไมมลกษณะ Integrated zero หรอเรยกสนวา I(0)

• ทาไมเราไดผลความสมพนธทมระดบนยสาคญทงๆท ตวแปรของเราไมนาจะสมพนธกน คาตอบคอ เมอเราประมาณแบบจาลอง เราจะไดคา 훽 และ se(훽) ซงเมอเราคานวณคา se(훽) ในแบบจาลองทเปน spurious เราจะไดคา se(훽) ทตาหรอสงเกนไปกวาทควรจะเปน t-stat กเลยผด การทดสอบระดบนยสาคญกเลยผดตาม

• วธการแกไขเบองตนคอ เมอเราขอมลไมมงนงก transform มนนงกอนแลวคอยนาไปประมาณในแบบจาลองตอไป หรอเราอาจ transform โดยใชวธ first difference หรอ 훥푦 หรอทาใหขอมลมลกษณะ I(1) นนเอง

Page 33: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Spurious Regression (การถดถอยทไมแทจรง)

• Example

สมมตวาแบบจาลองน 푌 และ 푋 ไมมลกษณะไมนง แสดงวาเราอาจเดาไดวาแบบจาลองขางตนอาจมปญหา Spurious ขน ดงนนเราตองแกโดยทาการแปลงขอมลใหนง ดงน

เลอกวธใดวธหนงไปประมาณหาคา 훽 โดยวธ OLS ( อยาลมเอาตวแปรทเราแปลงไปเชค Unit root test กอน)

푌 = 푋 훽 + 푢

ln푌 = ln푋 훽 + 푢 −→ วธท 1훥푌 = 훥푋 훽 + 푢 −→ วธท 2

훥ln푌 = 훥ln푋 훽 + 푢 −→ วธท 3

Page 34: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ถาเราไมอยากแปลงขอมล เนองจากกลวแปลผลยาก เราจะทาอยางไร?

คาตอบ เราสามารถประมาณผลตามปกตได ถาเราพบวาแบบจาลองของเรามลกษณะทเรยกวา Cointegration หรอก

คอ มลกษณะ Long run relationship นนเอง

Cointegration คออะไร

คาตอบ คอภาวะทถงแมวาตวแปรขอมลมลกษณะไมนง เชน X และ Y ไมเปน I(0) แตทงสองตวแปรยงม

ความสมพนธระยะยาว เนองจากมกลไกบางอยางในการปรบตวในระยะสน ทาใหในระยะยาวแลว X และ Yสมพนธกน

ตวอยาง GDP และ Consumption เรารวามความสมพนธกนแนนอน สมมตเราไมรอะไรเลยและทาการเกบขอมล 10 ป

เราพบวา GDP และ Consumption ไมนงเลย ทาใหเราหาความสมพนธไดยาก ในป 1-2 ทเราทาการเกบขอมล แตเรา

พบวาปท 3 เปนตนไป เรมมการเคลอนไหวทสมพนธกนมากขน เราจะเรยกชวงนกวาชวงการปรบตวในระยะสน และเรมกลบมามความสมพนธอกในปท 4-10 ดงนนเราจะเหนวามชวงของการปรบตวอย ซงชวงระยะสนในปท 3 เราเรยกวาการปรบตว

ระยะสน (Short run adjustment) การปรบตวในปท 3 อาจเกดมาจากหลายสาเหต เชน การแทรกแซงของรฐบาล เปนตน

Spurious Regression (การถดถอยทไมแทจรง)

Page 35: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

1. ทาการตรวจสอบวา 푋 และ 푌 เปน integration order อะไรโดยใช ADF test - ถาพบวาตวแปรอยางนอยหนงตวไมมลกษณะนงท I(0) เราจะตองทาการทดสอบ Cointegration - ถาพบวาตวแปรทกตวมลกษณะนงท I(0) เราไมตองทาการทดสอบแลวเราประมาณแบบจาลองตอไปไดเลย

2. ทดสอบ Cointegration ระหวาง 푋 และ 푌 .ทาไดดงน

t t tY X u

การทดสอบ Cointegration Engle and Granger (1987)

Step 1 : ประมาณแบบจาลอง

Step 2 : หาคา error

Step 3 : check ความนงของ error โดย ADF test

t t tu Y X

Page 36: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• Augmented DICKEY–FULLER TEST

11

P

t t p t p tp

u u u

11

P

t t p t p tp

u u u

11

P

t t p t p tp

u u u t

กรณไมมคาคงทและคาแนวโนม

กรณมคาคงทและไมมคาแนวโนมเวลา

กรณมคาคงทและมคาแนวโนมเวลา

การทดสอบ Cointegration Engle and Granger (1987)

Page 37: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การทดสอบภายใต DICKEY–FULLER TEST

• ในกรณเราจะดวา คา 훾 =0 หรอไม ดงนนเราจะตงสมมตฐานไดวา

0

1

: 0 ( nonstationary) non-cointegration: 0 ( stationary) cointegration

t

t

H u isH u is

Step 4 : ทดสอบสมมตฐาน

การทดสอบ Cointegration Engle and Granger (1987)

Page 38: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Warning: ในการทดสอบความนงโดย ADF test เราจะไมใชตารางสถต critical value แบบปกตทวไปหรอของ ADF แตเราจะใชของ Engle-Granger (1989) หรอ McKinnon (1990) แทน

( 1.65) 5% Normal distribution( 2.86) 5% Dickey-Fuller distribution( 3.34) 5% Engle-Granger/McKinnon

P tP tP t

การทดสอบ Cointegration Engle and Granger (1987)

Page 39: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Error Correction Model(ECM)

ถา 푋 , 푌 มลกษณะ cointegration ดงนนเราจะเราสามารถประมาณแบบจาลองปกตไดเลยเนองจากไมเกด Spuriousในแบบจาลองของเรา

คาถามตอมาคอ เราแบบจาลองของเรามความสมพนธระยะยาวหรอ cointegration ไดอยางไร

คาตอบคอ มนมการปรบตวในระยะสน นนเอง และเราสามารถวเคราะหการปรบตวระยะสนได โดยใช ECM ซงม

ลกษณะดงน

• พดงายๆ กคอ เมอ Y เบออกจากความสมพนธระยะยาวกบ X ECM จะทาหนาทดงตวแปร Y กลบ

เขามาสมพนธกบ X เหมอนเดม

0 1 1t t t tY u X v 0 1 1t t t tY u X v

• คา 휌 มความสาคญมากในแบบจาลองน เนองจากแสดงวา ECM ทาหนาทในการในการดงเขา Y ใหเขาท

เขาทางไดเรวแคไหน ซงคาทเหมาะสมคอ -1< 휌 < 0 เราเรยกคาๆ นวา speed of adjustment

Page 40: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Geometric ของ Error Correction Modelการทางานของ ECM

tY

tX

t tY X0tu

Short-run dynamics: การปรบตวใน short run โดย ECM จะทาใหเกดความสมพนธ

ระหวาง X ตอ Y ในดลยภาพระยะยาว (Long-run equilibrium)t tY X

Page 41: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การใชโปรแกรมทางเศรษฐมต

• R program• Eviews

Page 42: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Spurious regression# Simulate Y and XT <- 1000set.seed(1357)y <- ts(rep(0,T))vy <- ts(rnorm(T))for (t in 2:T){

y[t] <- y[t-1]+vy[t]}set.seed(4365)x <- ts(rep(0,T))vx <- ts(rnorm(T))for (t in 2:T){x[t] <- x[t-1]+vx[t]}y <- ts(y)x <- ts(x)ts.plot(y,x, ylab="y and x")

Page 43: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Plot Result

Time

y an

d x

0 200 400 600 800 1000

-40

-20

020

40

Page 44: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Spurious regression## Run regression with spurious regressionmodel=lm(y~x)summary(model)

Page 45: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Test Cointegration

# Step 1 : ทาการประมาณแบบจาลองทมลกษณะ spurious regressionmodel=lm(y~x)

# Step 2 : หา error จากแบบจาลอง regressionres=residuals(model)

# Step 3 : เชคความนงของ error โดยใช Package urcalibrary(urca)test1=ur.df(res,type="none",selectlags = c("AIC"))test2=ur.df(res,type="drift",selectlags = c("AIC"))test3=ur.df(res,type="trend",selectlags = c("AIC"))

Page 46: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Test Cointegration and ECM model

# import example datadata=read.csv(file.choose(),head=TRUE)attach(data)LR=lm(LY~LC )summary(LR)ecm=residuals(LR)test1=ur.df(ecm,type="none",selectlags = c("AIC"))test2=ur.df(ecm,type="drift",selectlags = c("AIC"))test3=ur.df(ecm,type="trend",selectlags = c("AIC"))summary(test1)

ตวอยางการประมาณแบบจาลองทมลกษณะ Cointegration ในตวอยางน เราจะศกษาผลกระทบของ การบรโภค

(Consumption) ตอ รายได (Income) โดยขอมลเอามาจาก usdata.csv

Page 47: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ตวอยางผลของการทดสอบความนงของ error (กรณ no intercept and Trend)

Page 48: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

# ECM modeln=length(LY)dLY=c(0,diff(LY))dLC=c(0,diff(LC))ecm1=c(0,ecm)[1:n]SR=lm(dLY~dLC+ecm1)summary(SR)

R code: Test Cointegration and ECM model

Page 49: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ผลการประมาณ ECM

Page 50: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 1 นาขอมลเขา)

ตวแปร LC และ LY

Page 51: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 2 Unit root test)

Page 52: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 3 ประมาณ Long run regression)

Page 53: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 3 ประมาณ Long run regression)

Page 54: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 4 Test cointegration)

Page 55: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 4 Test cointegration)

Page 56: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 4 Test cointegration)

Page 57: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 4 Test cointegration)

Check Unit root test ของ คา ECM

Page 58: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ECM (STEP 5 Run ECM ) Run regression นนเอง

Page 59: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eview : ผลการประมาณการปรบตวระยะสน ECM

Page 60: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบฝกหด บทท 2 (ทฤษฎ)

• 1. ECM และ Cointegration มความเกยวพนกนอยางไร

• 2. สมการ Regression และสมการ ECM เหมอนหรอแตกตางกนอยางไร

• 3. ถาเราพบวา ตวแปร Y มลกษณะ I(0) และ 푋 และ 푋 นงท 퐼 1 และ 푋 มลกษณะนงท 퐼 2เมอพบสถาณการณแบบน นกศกษาจะทาการประมาณอยางไรตอไป จงอธบายความเปนไปไดทงหมด ทจะทาได และใหเหตผลประกอบคาอธบาย

• 4. ถาเราอยากทราบวา การปรบตวในระยะสนของความสมพนธระหวาง X และ Y เราจะตรวจสอบไดอยางไร

Page 61: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบฝกหด บทท 2 (Code)

จงทาการประมาณสมการ โดยใชขอมลจาก UStreasury10.xlsx

1) ถาเราตองการศกษาวา ผลตอบแทนของตวเงนคลงอาย 3 เดอน (푇퐵3) มผลตอผลตอบแทนของพนธบตรรฐบาล (퐺푆10) หรอไม อยางไร จงแสดงผลการศกษาพรอมกบขนตอนในการศกษา โดยละเอยด

2) ถาเราตองการศกษาวา ถาตวเงนคลงอาย 3 เดอน (푇퐵3) เปลยนแปลงไป 1 % จะมผลกระทบพนธบตรรฐบาล (퐺푆10) หรอไม อยางไร จงแสดงผลการศกษาพรอมกบขนตอนในการศกษา โดยละเอยด

หมายเหต นกศกษาสามารถใช Eview หรอ R code อยางใดอยางหนงกได และแสดงผลการประมาณ พรอมอธบายพอสงเขป

10 ( 3)GS f TB

Page 62: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Chapter 4Volatility model

Dr. Woraphon Yamakahttps://wyamaka.wordpress.com

Page 63: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Volatility คอ VARIANCE นนเอง• ตอนเราทา linear regression กเพอศกษาวา x สงผลตอ y อยางไร หรออกเปาหมายหนงก

คอ เราตองการพยากรณ y นนเอง โดยมสมการดงน

หรอ

• Mean ของแบบจาลอง คอ 푋훽

• Variance ของแบบจาลอง คอ 휎 ซงเรามกสมมตใหมนนง และคาคงท เรยกวา homoscedastic

• แตในความเปนจรงแลว ขอมลอนกรมเวลาตางๆ มกไมนง ดงนนการทเราสมมตให 휎 คงทอาจจะผด นกเศรษฐมตหลายคน จงเชอวา 휎 ไมนง หรอมลกษณะ heteroscedastic 63

2( , )y N X

y X u

Page 64: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

VARIANCE หรอ Volatility

• การท σ ไมนง หรอมลกษณะ heteroscedastic นนมกเกดจากความผนผวนของขอมลตวแปร Y นนเอง

• ดงนนในบทนเราจะไมสนใจ Mean หรอ Xβ แตเราจะสนใจการประมานความผนผวนมากกวา

• Volatility นจะชวยใหเราสามารถดความผนผวนของขอมลทางเศรษฐกจได วามมากหรอนอยเพยงใด เชน ความผนผวนของ GDP, ราคาหน และคาเงน เปนตน

• ทผานมาเราประมาณความผนผวนของ Y โดย

Var(Y) =E(YE(Y))2

64

2 2

1/ ( ) / ( )

T

tt

u T k u u T k

วธทางเศรษฐมตเบองตน ทสมมตให Variance คงท

วธทางสถต

วธทางเศรษฐมตเบองตน ทสมมตให Variance ไมคงทแบบจาลอง Volatility ในบทท 4 2t

Page 65: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

VARIANCE หรอ VolatilityConditional Variance หรอกคอ Variance ทเปลยนแปลง

ไปตามเวลานนเอง

meanvariance

Conditional variance

65

2t

2t

2

Page 66: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

66

ม.ค. 03 2000 เม.ย. 02 2001 ก.ค. 01 2002 ก.ย. 02 2003 ธ.ค. 01 2004 ม.ค. 01 2006 ม.ย. 01 2007 ส.ค. 01 2008 ต.ค. 01 2009 ธ.ค. 01 2010 ม.ค. 01 2012 ม.ย. 03 2013 ก.ย. 02 2014

S&P 500

-0.05

0.00

0.05

0.10

2000 2005 2010

0.00

0.05

0.10

0.15

Forecast Rolling Sigma vs |Series|

Time/Horizon

Sigm

a

GAR

CH m

odel

: s

GAR

CH

Horizon: 3520

Actual

Forecast

|Series|

Page 67: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ประเภทของ Volatility Model

1. ARCH2. GARCH3. INTEGRATED GARCH (IGARCH)4. Exponential GARCH (EGARCH)5. Threshold GARCH (TGARCH)6. Glosten Jaganathan Runkle-Generalized AutoregresiveHeteroskedascticity (GJR-GARCH) 7. GARCH in Mean (GARCH-M)8. Markov Switching GARCH (MSGARCH)

Page 68: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ขอมลแบบใดทมลกษณะทเรยกไดวา Volatility?Stylized Facts of asset returnsi. Leptokurtic: ขอมลมลกษณะการแจกแจกงทหางหนา

ii. Volatility clustering: สามารถสงเกตเหนความผนผวนเปนกลมๆ ชดเจน

iii. Leverage Effects: ความผนผวนจะมความสมพนธตรงขามกบ Y

iv. Non-trading period effects: ความผนผวนของตลาดหนในวนจนทร มกสงกวาวนองคาร เพราะวนเสาร-อาทตย ตลาดหนปด ทาใหหนไมสามารถตอบสนองตอขาวตางๆ ได จงทาใหเมอตลาดเปดในวนจนทร ราคาหนจงปรบเปลยนสงมาก

v. Forecastable events:ความผนผวนจะสงเมอมเหตการณ สาคญเกดขน แตจะนงถาไมมขาวสารอะไรใหมๆเขามาเลย

68ม.ค. 03 2000 เม.ย. 02 2001 ก.ค. 01 2002 ก.ย. 02 2003 ธ.ค. 01 2004 ม.ค. 01 2006 ม.ย. 01 2007 ส.ค. 01 2008 ต.ค. 01 2009 ธ.ค. 01 2010 ม.ค. 01 2012 ม.ย. 03 2013 ก.ย. 02 2014

S&P 500

-0.05

0.00

0.05

0.10

normal distribution with time varying volatility

Y

Freq

uenc

y

-0.4 -0.2 0.0 0.2 0.4

050

100

150

200

250

300

normal distribution with constant volatility

rnorm(1000)

Freq

uenc

y

-3 -2 -1 0 1 2 3

050

100

150

200

Page 69: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

1.) ARCH(q) MODEL

• ARCH (autoregressive conditionally heteroscedastic) Engle(1982)

69

1

2 21 0 1 1

01

~ 0,

0, 0, 0 1, 1,

t t t

t t t

t t t

t t t t q t q

q

i ii

Y XY X

N h

Var h

i q

This model is called a “ Linear ARCH(q) Regression “ model.

2*** t th

Mean Equation

Variance Equation

Page 70: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การทดสอบการมอยของ ARCH effect

• Method 1. ทาการทดสอบ residual วามปญหา autocorrelation หรอไม

70

1t tu u 0 2 2

1t tu u 0 ARCH effects

Page 71: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• Method 2. Lagrange Multiplier ( LM ) TestStep 1: HyphothesisH0 : no ARCH H1: ARCH effects

Step 2 test for first-order ARCH

Step 3: LM-test

71

การทดสอบการมอยของ ARCH

2

2 20 1 1

t t t

t t t

Y X uu u v

1 2

2 20.05,stat ( ) , k kLM T q R

1 0 1 0

1 2

2 200.05,if ( ) , Rejectk kT q R H

Page 72: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ESTIMATION ARCH(q) : Maximum likelihood Estimator (MLE)

• Let the log likelihood function for the model is

2 20 1 1

2

1

1 1log ln2 2

t t t

t t q t q

nt

tt t

Y Xh

l hh

72

2

2

arg max(log )

log; 0

log; 0

l

lFOC

lSOC

Page 73: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ปญหาของแบบจาลอง ARCH

• ในการประมาณแบบจาลอง ARCH ถาเราม lag q ทสงเกนไป มกจะทาใหการประมาณℎ < 0 =⇒ negative variance และ non-stationarity.

• เวลาเราแกปญหา เราสามารถทาไดโดยการ จากด lag q ไมใหสงกนไป แตปญหากคอ เราอาจไดแบบจาลอง ARCH ทไมสามารถวดความผนผวนไดด เนองจากไมสามารถ แกปญหา ขอมลทม Long memory ไดนนเอง

• ดงนน Bollerslev,1986 เสนอใหทา Generalized ARCH (GARCH)

73

Page 74: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

20

1 1

p q

t i t i j t ji j

h h

0

1 1

0, 0, 0, 1, , , 1,

1

i j

q p

i ji j

i q j p

จากโครงสรางจะเหนวาสมการ GARCH มลกษณะโครงสรางแบบ ARMA(p,q)

2) GARCH (Bollerslev,1986)

• แบบจาลอง GARCH (q, p) มลกษณะดงน

74

MA(q) AR(p)

Page 75: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

GARCH MODEL

•ตวอยาง GARCH(1,1)

75

1

20 1 1 1 1

~ 0,t t t

t t t

N h

h h

Page 76: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

TESTING FOR GARCH DISTURBANCES• METHOD 1: ใชวธการเดยวกบ LM test ของ ARCH เลย

• METHOD 2: ใช LR testStep 1: HypothesisH0 : ARCH effectsH1: GARCH effectsStep 2 test for first-order GARCH(1,1)

Step 3: LR-test

76

20 0 1 1

21 0 1 1 1 1

:

:t t

t t t

H h

H h h

1 2

200.05,if stat , Rejectk kLR H

1 2

20.05,stat 2 ln log ( ) / log ( ) , k kLR l GARCH l ARCH

푘1 คอจานวน parameter ของ unrestricted model ซงในกรณน คอ GARCH model푘2 คอจานวน parameter ของ unrestricted model ซงในกรณน คอ ARCH model

Page 77: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

3) INTEGRATED GARCH(p,q)

• อยางไรกตาม ถาเราพบวา

เราจะพบปญหา unit root ใน ℎ

เราควรใช Integrated GARCH

โดยท เทานน77

1 11,

q p

i ji j

20

1 1.

q p

t i i j t ji j

h h

1 11

q p

i ji j

Page 78: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

SYMMETRYCITY OF GARCH MODELS

• ในแบบจาลองขางตนทกลาวมา ARCH, GARCH และ IGARCH เราจะสมมตใหผลกระทบของ 휀 ตอ ℎ มลกษณะสมมาตร (Symmetry) กลาวคอ error ทเปน บวก หรอ ลบ มผลกระทบตอ conditional variance (ℎ ) เทากน

• อยางไรกตามในความเปนจรงขาวดกบขาวราย นาจะสงผลใหเกดความผนผวนทตางกน

• โดยปกตแลว Positive shock < negative shock

78

“leverage” effect.

Page 79: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

4) EGARCH(p,q) Nelson (1991)

• เปน GARCH รปแบบหนงทเปนลกษณะ asymmetric กลาว positive shock 휀 (+ และ

Negative shock 휀 (− สงผลตอ Volatility ℎ ตางกน

79

01 1

ln ln .q p

t i t i j t ji j

h h

Page 80: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

5) AGARCH

• An asymmetric GARCH AGARCH(p,q)

20

1 1.

q p

t i t i j t ji j

h b h

Page 81: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

5) GJR-GARCH

• The GJR GARCH model สามารถเขยนไดดงน

2 20

1 1 1,

q p q

t i t i j t j i t i t ii j i

h h I

1 00 0

t it i

t i

ifI

if

.

ขาวราย

ขาวด

Page 82: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

THRESHOLD GARCH (TGARCH)

• Glosten, Jaganathan and Runkle (1994) เสนอ TGARCH ซงเปนแบบจาลองทมลกษณะ asymmetric เชนกน

82

01 1

( )q p

t i t i i t i j t ji j

h h

Page 83: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

GARCH in MEAN (GARCH-M)

0 1t t ty h

20

1 1

q p

t i t i j t ji j

h h

83

Mean Equation

Variance Equation

Engle Lilien and Robins(1987) กลาววาความผนผวน สามารถทจะสงผลตอตวแปร Y ท

อยใน สมการ Mean ได ดงนนจงเสนอแบบจาลอง GARCH in Mean ขนมา

Page 84: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Special GARCH

84

ปกตแลว GARCH มกสมมตวาขอมลความผนผวนมการแจกแจงแบบปกต (Normal distribution) ซงในความเปนจรงแลว ขอมลในปจจบนมกจะไมมการ

แจงแจงแบบปกต โดยเฉพาะขอมลทางการเงน

ดงนนในปจจบนจงมการเสนอให GARCH ประมาณภายใตขอสมมต ของการแจกแจงอยางอน เชน

휀|휓 ~푆푁 0,    ℎ

휀|휓 ~푇 0,    ℎ

휀|휓 ~푆푇 0,    ℎ

Skewed Normal

Student-t

Skewed student-t

Page 85: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Programming• Rcode• Eviews

Page 86: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH test (SET.xlsx)library(rugarch)library(dynlm)#====== Step 1 Import data ===============#data=read.csv(file.choose(),header=TRUE)attach(data)dailyreturn<-diff(log((set)))plot(ts(dailyreturn, start=c(2008,1,2), freq=252), ylab="return",main="SET index return" )hist(dailyreturn, main="SET index return" )#====== Step 2 ARCH (1) Mean Model===============#meanEq <- dynlm(dailyreturn ~1)summary(meanEq)#====== Step 3 ARCH(1) Variance Model ===============#ehatsq <- ts(resid(meanEq)^2)ARCH <- dynlm(ehatsq~L(ehatsq,1))summary(ARCH)

Page 87: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ผลการรน ARCH(1)Call:

dynlm(formula = ehatsq ~ L(ehatsq, 1))

Residuals:

Min 1Q Median 3Q Max

-0.0028743 -0.0001192 -0.0000982 -0.0000084 0.0107715

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 1.143e-04 1.055e-05 10.83 <2e-16 ***

L(ehatsq, 1) 2.812e-01 1.994e-02 14.10 <2e-16 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.0004847 on 2316 degrees of freedom

Multiple R-squared: 0.07907, Adjusted R-squared: 0.07867

F-statistic: 198.9 on 1 and 2316 DF, p-value: < 2.2e-16

Page 88: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH test (SET.xlsx)#====== Step 4 LM test ===============#T=length(dailyreturn)

k1 <- 1

k2 <- 2 #ARCH ม 2 พารามเตอร

Rsq <- 0.07907

LM <- (T-k)*Rsq

alpha <- 0.05

Chicr <- qchisq(1-alpha, abs(k1-k2))

pvalue =1-pchisq(Chicr, T-k, lower.tail = FALSE)

pvalue[1] 0> Chicr[1] 3.841459> LM [1] 183.1261

# คาตอบคอ p-value = 0 และ LM>Chicrเราจงปฎเสธ H0 ดงนนขอมล SET ม ARCH effect

Page 89: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH and GARCH model (SET.xlsx)library(rugarch)library(dynlm)#====== Step 1 download data ===============#data=read.csv(file.choose(),header=TRUE)attach(data)dailyreturn<-diff(log((set)))plot(ts(dailyreturn, start=c(2008,1,2), freq=252), ylab="return",main="SET index return" )hist(dailyreturn, main="SET index return" )

Page 90: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

GARCH(q) MODEL

• ARCH (autoregressive conditionally heteroscedastic) Engle(1982)

1

2 21 0 1 1

~ 0,

t t

t t

t t t

t t t t q t q

YY

N h

Var h

Mean Equation มแค

intercept term (휇) ตวเดยว

Variance Equation

Page 91: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH and GARCH model (SET.xlsx)#====== Step 2 Select GARCH TYPE ===============#

# ARCH(1) == GARCH(1,0) model

arch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)), variance.model = list(model = "fGARCH", garchOrder = c(1, 0), submodel="GARCH"), distribution.model = "norm")

# GARCH(1,1) model

garch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)), variance.model = list(model = "fGARCH", garchOrder = c(1, 1), submodel="GARCH"), distribution.model = "norm")

# IGARCH(1,1) model

Igarch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)),variance.model = list(model = "iGARCH", garchOrder = c(1, 1)), distribution.model = "norm")

# TGARCH(1,1) model

Tgarch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)), variance.model = list(model = "fGARCH", garchOrder = c(1, 1), submodel="TGARCH"), distribution.model = "norm")

# AGARCH(1,1) model

Agarch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)), variance.model = list(model = "fGARCH", garchOrder = c(1, 1), submodel="AVGARCH"), distribution.model = "norm")

Page 92: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH and GARCH model (SET.xlsx)#====== Step 2 Select GARCH TYPE ===============#

# GJRGARCH(1,1) model

GJRgarch<-ugarchspec(mean.model = list(armaOrder = c(0, 0)), variance.model = list(model = "fGARCH", garchOrder = c(1, 1), submodel="GJRGARCH"), distribution.model = "norm")

# GARCH(1,1) in Mean model

garchM<-ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),

mean.model = list(armaOrder = c(0, 0),include.mean = TRUE,archm = TRUE, archpow =2), distribution.model = "norm")

Page 93: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code ARCH and GARCH model (SET.xlsx)

#====== Step 3 Maximum Likelihood Estimator EX: GARCH-M

modelfit<-ugarchfit(spec=garchM,data=dailyreturn)

modelfit

Page 94: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

#====== Step 4 Plot Volatility EX: GARCH-M ===============#

hhat <- ts(modelfit@fit$sigma^2)

plot(ts(hhat, start=c(2008,1,2), freq=252), ylab="volatility",main="SET index volatility")

SET index volatility

Time

vola

tility

2008 2010 2012 2014 2016

0.00

000.

0010

0.00

200.

0030

Page 95: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model

• Step 1 ขอมลเขา EVIEW โดยใชขอมล จาก SET.xlsx

Page 96: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model

• Step 1 ขอมลเขา EVIEW โดยใชขอมล จาก SET.xlsx

Page 97: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model• Step 2 เรมรน GARCH

(1) กด quick

(2) Click

(3) พมพ set c

Page 98: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model• Step 2 เรมรน GARCH

(1) กด quick

(2) เลอก ARCH

(3) เลอกชนดของ GARCH (4) เลอกชนดของ order GARCH(p,q) ตวอยาง คอ

GARCH(1,1)

(5) เลอก distribution ของ GARCH

(6) กด OK

Page 99: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model

• Step 4 Plot Volatility

Page 100: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model• Step 4 Plot Volatility

(1) กด view

(2)

(3)

Page 101: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Eviews GARCH model• ผลการ plot volatility

หมายเหต โปรแกรม Eview ทาไดแคบางประเภทของ GARCH และ distribution นน เชน ARCH, GARCH,TGARCH, EGARCH และ IGARCH (normal, student-t, GED) ไปด STEP 2

Page 102: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบฝกหดทายบทท 4 (ทฤษฎ)

1) สมการ Mean และสมการ Variance เหมอนหรอตางกนอยางไร และเมอใดเราจะเลอกใช Mean และเมอใด เราจะเลอกใชสมการ Variance จงยกตวอยางใหพอเขาใจ

2) สมมตวาเรามขอมล Y จานวน T=100 เราทาการประมาณสมการ GARCH(1,2) แลวพบวาคา likelihood = 150 และเมอประมาณสมการ ARCH(2) พบวามคา likelihood = 120 จงแสดงวธการทดสอบวาแบบจาลองขอมล Y นม GARCH effect และ ARCH effect หรอไม

3) สมการ GJR-GARCH คอ

ถา 휑 มคาเทากบ 0 และ 휀 = −2 เราจะเขยนสมการ GJR-GARCH ใหมไดอยางไร และถาเทยบกบแบบจาลอง GARCH ความผนผวนทคานวณไดจะเทากนหรอไม จงอธบาย

2 20 1 1 1 1 1 1,t t t j t th h I

1 00 0

t it i

t i

ifI

if

Page 103: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

แบบฝกหดทายบทท 4 (Practice) ใชขอมลราคาจาก singapore.xlsx1) จงทดสอบวา ผลตอบแทนของ SET index ม ARCH effect หรอไม โดยใช R หรอ EViews ก

ได จงแสดงผลและแปลผลการศกษา

2) สมมตวา order GARCH(2,2) เปนรปแบบท order ดทสด จงทาการทดสอบดวาแบบจาลองประเภทใดของ GARCH ทสอนในบทท 4 เปนแบบจาลองทดทสด จงเขยน Code และแสดงวธการเลอกแบบจาลองของนกศกษา และสดทาย จงแปลผลการศกษาและ plot ความผนผวนดวย (ขอใหสง code แนบทายคาตอบดวย)

Page 104: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Chapter 5Panel regression model

Dr. Woraphon Yamakahttps://wyamaka.wordpress.com

Page 105: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Panel regression model• แบบจาลองมลกษณะเหมอนกนกบแบบจาลอง linear regression แต

แทนทเราจะใชขอมล ภาคตดขวาง(cross section) หรอ อนกรมเวลา (Time series) แบบจาลองนเราเลอกใชขอมล Panel แทนทขอมล 2 ประเภท ขางตนเทานนเอง ดงนนเราเลยตงชอวา

• Panel regression

105

Page 106: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ทบทวน : 1. ลกษณะภาคตดขวาง(cross section)

• เปนขอมลทเกบจากหนวยตวอยาง (entities) หรอ ปจเจกบคคล (individuals) ทแตกตางหรอเปนอสระ

ตอกน ณ จดเวลาใดเวลาหนง

เชน

106

Page 107: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ทบทวน : 2. ลกษณะรวมภาคตดขวาง(Pooled cross section)

• ขอมลรวมภาคตดขวาง (Pooled cross-sectional data) คอ ขอมลทม

ลกษณะเปนทงภาคตดขวาง (Cross section) และอนกรมเวลา (Time series)

กลาวคอ เปนการรวบรวมขอมลจากหนวยตวอยางทเปนอสระจากกน และ

เกบขอมลในจดเวลาทตางกน (รวมหลายๆ Cross sectional data เขา

ดวยกน)

• ขอสงเกต หนวยตวอยางจะตองแตกตางกนในแตละจดเวลา

107

Page 108: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

108

ขอมลจาก 100

หลง ในป 2000

ขอมลจากอก 2

หลงใหม ในป 2010

• หนวยตวอยางตองถกเลอกแบบสม

• บานทง 102 ถกเกบขอมลครงเดยว (ปทเกบอาจตางกน) โดยในป 2000 ม

จานวน100 หนวยตวอยาง และในป 2010 ม 2 หนวยตวอยาง

ทบทวน : 2. ลกษณะรวมภาคตดขวาง(Pooled cross section)

Page 109: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• การเลอกใชขอมลรวมภาคตดขวางมวตถประสงคทสาคญคอ เพอเพมขนาดของ

ตวอยาง โดยมขอสมมตวาตวแปรตนและตวแปรตามมความสมพนธทคงท

ในระยะยาว

• โดยทวไปแลวการวเคราะหขอมลรวมภาคตดขวาง จะแกปญหาเรองเวลาท

แตกตางกนภายในชดขอมลโดยกาหนดให “เวลา” เปนตวแปรหน และเพมตว

แปรหนเวลา (time dummy) เขาในแบบจาลอง

109

ทบทวน : 2. ลกษณะรวมภาคตดขวาง(Pooled cross section)

Page 110: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• คอ ขอมลทเกบจากหนวยตวอยาง i ในชวงเวลาตางๆ ทาใหขอมลแตละชวงเวลาไมเปนอสระตอกน

• ขอมลนเปนการตดตามบคคล ครวเรอน หนวยธรกจ จงหวด ประเทศ ในชวงเวลาตาง ๆ โดยเชอวาจะมพฤตกรรมทเปลยนแปลงไปเมอเวลาเปลยนไป

• เชน - ขอมลคาจางของบคคลคนเดยวกนในป 2552 และ 2553

- ผลประกอบการของบรษทในป 2010 และ 2013 เปนตน

• เชอวาลกษณะเฉพาะของแตละหนวยขอมล หรอ ความแตกตางระดบปจเจกบคคล (Individual) จะมผลตอตวแปรทสนใจศกษา แตไมสามารถสงเกตได (Unobservable factors)

110

ทบทวน : 3. ลกษณะพาแนล (Panel data หรอlongitudinal data)

Page 111: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

111

• ขอมลของ 3 ประเทศ (i=3) ตงแต

ป 2000 ถง 2002 (t=3)

• จานวนคาสงเกต (Observation):푛 = 푖 × 푡 โดย i=1,…,I ,

t=1,…,T

ดงนน กรณน n=9

• หนวยตวอยางตองถกเลอกแบบ

สม

• แตละประเทศถกตดตามเกบขอมล

3 ครง คอในป 2000, 2001 และ

2002

Page 112: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• สมมตวาเกบขอมลจาก 30 หนวย และชวงเวลา 7 ป นนคอ i=30 และ t=7 ดงนน จานวน Observation จะเทากบ 210 หนวย

• ขอมลทมคาสงเกตครบทง 210 หนวย เรยกวา ขอมลชวงยาวทสมดล (Balanced panel)

• หากมคาสงเกตบางคาหายไป ไมครบ 210 หนวย (ขอมลไมครบทกป) เรยกวา ขอมลชวงยาวทไมสมดล (Unbalanced panel)

112

ทบทวน : 3. ลกษณะพาแนล (Panel data หรอlongitudinal data)

Page 113: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• ประโยชนของ Panel data คอ สามารถสะทอนการเปลยนแปลงพฤตกรรมของแตละหนวยตวอยางเมอเวลาเปลยนแปลงไปได

• โดยพฤตกรรมทเปลยนแปลง อาจเกดจากปจจยทไมสามารถสงเกตได เชน วฒนธรรม ความสามารถของบคคล วธการดาเนนงานของธรกจ เปนตน รวมถงปจจยอนๆ ทเปลยนแปลงไปตลอดเวลา และมสวนทาใหคาของตวแปรตาม หรอตวแปรทเราสนใจศกษา เปลยนแปลงไป

• ขอจากดของ Panel data คอ การจดเกบขอมลททาไดยาก โดยเฉพาะ macro panels เชน ขอมลของแตละประเทศในกลมใดกลมหนง เปนตน ซงตองมจานวนเทากน

113

ทบทวน : 3. ลกษณะพาแนล (Panel data หรอlongitudinal data)

Page 114: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

114

จากตวอยางขอมล Panel คอม 3 ประเทศ เกบขอมล 2000-2002 (3ป) เราสามารถนามาสราง

แบบจาลองถดถอยไดเปน

โดยท 훼 แทน individual fixed effect

훿 แทน time fixed effect

푌= 훽 푋1 + 훽 푋2 + 훽 푋3 + 훼 + 훿 + 푢

Page 115: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การวเคราะหขอมล Panel

• ขอมลPanel หมายถง ขอมล i หนวย ทสงเกตไดใน T ชวงเวลา ดงนนการแสดงขอมลชวงยาวจงทาได ดงน

X , Y โดยท i = 1,…,I และ t = 1,…,T

• ในหวบทนจะกลาวถงวธการวเคราะห Panel data regression 2 วธ ไดแก • Fixed effect

• Random effect

115

Page 116: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Fixed effects

ตวอยาง อบตเหตในทองถนนกบภาษแอลกอฮอล

• เนองจากอบตเหตในทองถนนสวนใหญเกดจากการดมเครองดมทมแอลกอฮอล

ดงนน รฐบาลสหรฐฯ จงออกนโยบายทจะลดอปสงคการดมแอลกอฮอลลง

• สมมตวารฐบาลสนใจศกษาอตราการตายจากอบตเหตการจราจรตอประชากร

10,000 คน ในแตละรฐ และใชภาษเบยรเปนเครองมอของนโยบายรฐบาล

กาหนดใหตวแปร คอ

o FR (Fatality rate) คอ อตราการตายจากอบตเหตการจราจรตอประชากร 10,000 คน

o Beer tax คอ ภาษเบยร (USD per case $1988)

116

Page 117: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• สมมตวาทาการศกษาใน 2 ชวงเวลาคอ ป 1982 และป 1988 หากนาขอมลแตละป มาทาการประมาณสมการถดถอยจะพบวา

• ในป 1982 อตราการตายเทากบ

FR = 2.01 + 0.15BeerTax(0.15) (0.13)

• ในป 1988 อตราการตายเทากบ

FR = 1.86 + 0.44BeerTax(0.11) (0.13)

117

Fixed effects

Page 118: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

118

รปท 7.1 อตราการตายบนทองถนนและภาษเบยรในป 1982 และป 1988

ป 1982

Fixed effects

Page 119: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

119

ป 1988Fixed effects

Page 120: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• ทงสองสมการแสดงใหเหนวา การเพมภาษทาใหอตราการตายเพมขน

• สาเหตของ “ผลบวก” เพราะมการละเลยตวแปรทสาคญบางตวไป

เนองจากอตราการตายจากอบตเหตบนทองถนน ไดรบอทธพลจากหลายปจจย เชน

คณภาพรถยนตทใชในแตละรฐ ลกษณะถนนของแตละรฐ กฎหมายทเกยวกบการขบรถยนตและ

การดมแอลกอฮอล หรอลกษณะทางสงคมและวฒนธรรมของแตละรฐ เปนตน

• วธการแกปญหา => เพมตวแปรลงไปในแบบจาลอง

แตอยางไรกตาม ตวแปรบางตวไมสามารถสงเกตหรอวดได เชน ลกษณะทางสงคมและ

วฒนธรรมของแตละรฐ

• แตถาปจจยทสงเกตไมไดนน มลกษณะคงทตลอดชวงเวลาทศกษา เชน วฒนธรรมไมเปลยน

กจะสามารถแกปญหานไดโดย

1. การทา Differencing (Difference-in-Difference) (ประมาณดวย OLS)

2. การประมาณสมการถดถอย ทม Fixed effects (ประมาณดวย OLS)

120

Fixed effects

Page 121: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

1. การทา Differencing (Difference-in-Difference)

• สมมตให Z เปนตวแปรอสระทมผลตออตราการตายของรฐ i แตไมเปลยนแปลงตามเวลา เชน คานยมทาง

วฒนธรรมและสงคม

• แบบจาลองความสมพนธระหวางอตราการตายและตวแปรอสระตางๆ จะเปน

FR = β + β BeerTax + β Z + u

• ดงนน แบบจาลองสาหรบทง 2 ป (t=2; 1982 และ 1988) จะไดวา

FR = β + β BeerTax + β Z + uFR = β + β BeerTax + β Z + u

เศรษฐมต I 751703 121

Fixed effects

Page 122: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• นาทงสองสมการมาลบกน (ตามวธ Difference-in-Difference) ไดเปน

FR − FR = β − β + β BeerTax − BeerTax + u − u

วธนจาทาให Z และ β หายไป เนองจากเปนคาคงท มคาเทาเดมในแตละป

• สมมต ผลการประมาณทประมาณไดจากผลตางของอตราการตายและผลตางของภาษเบยร คอ

∆FR = −1.04∆BeerTax

122

-1.04 หมายถง การเปลยนแปลงภาษเบยรจะ

สงผลกระทบตออตราการตาย โดยการเพมขน

ของภาษ 1 USD จะทาใหอตราการตายลดลง

1.04 คนตอประชากร 10,000 คน

Fixed effects

Page 123: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

123

การเปลยนแปลงอตราการตายและภาษเบยรป 1982-1988

Fixed effects

Page 124: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• วธ Difference-in-Difference เหมาะสาหรบขอมลทม 2 ชวงเวลา แตในกรณท

ขอมลชวงยาวมมากกวา 2 ชวงเวลา จะใชวธกการประมาณสมการถดถอยทม

Fixed effects หรอ Fixed effect regression

• ให Zi เปนตวแปรทมคาแตกตางไปตามหนวย (entities) หรอปจเจกบคคล

(Individuals) แตไมเปลยนแปลงตามเวลา เชน วฒนธรรม คานยม

• แนวคดของแบบจาลองน คอ แบบจาลองจะมคา intercept เทากบจานวนหนวย

(i) ซงคา intercept จะรวมเอาอทธพลของ Zi เอาไว

124

2. Fixed effects (FE) Regression modelFixed effects

Page 125: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• แบบจาลองของสมการถดถอยทม Fixed effects สามารถแสดงไดดงน

Y = β + β X + β Z + u

โดย Y คอ อตราการตายจากอบตเหต

X คอ ภาษเบยร

Z คอ ตวแปรทไมสามารถสงเกตคาได แตไมเปลยนแปลงไปตามเวลา ในทน กาหนดใหเปน คานยมทางสงคมและวฒนธรรม

푖 คอ รฐในสหรฐอเมรกา (푖 = 1,2, … , 48)

t คอ ป ตงแตป 1982-1988 (รวม 7 ป)

ดงนน จานวน Observation (n) เทากบ (48)(7) = 336 หนวย

125

Fixed effects

Page 126: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• การประมาณคาสมประสทธ β มวตถประสงคเพอใหทราบอทธพลของตวแปร X ทมตอตวแปร Y กาหนดใหสงอน ๆ คงท รวมทงตวแปรทไมสามารถสงเกตได (Z)

• สมมตแตละรฐมความแตกตางกน และ ถกสมมตใหไมมผล ดงนน เราจะคานงเฉพาะความแตกตางของแตละรฐใน Z ดงนนเราจะเรยกแบบจาลองนวา Individual Fixed effect regression และสามารถเขยนใหมไดเปน

Y = β X + α + u• โดยท α = β + β Z

oพจน α ทาหนาทเปน intercept ของแตละรฐ (แตละหนวยททาการศกษา) ซงจะมคาแตกตางกนไปในแตละรฐแตจะไมเปลยนแปลงไปตามเวลา

oดงนน พจน α จงถกเรยกวา Entity fixed effects หรอ Individual fixed effects

126

Fixed effects

Page 127: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• ในทางปฏบต การประมาณสมการถดถอยทม Fixed effects ทาได 2 วธ

1. กาหนดตวแปรหน สาหรบแตละหนวย (Entity dummy)

2. วธ Demean

เศรษฐมต I 751703 127

Fixed effects

Page 128: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

1. Entity dummy

• การกาหนดตวแปรหนสาหรบแตละหนวย จะมจานวนตวแปรหนเทากบ i-1 เชน ทาการศกษาใน 48 รฐ (i=1,2,…,48) ดงนน จานวนตวแปรหน (D) เทากบ 47 ตวแปร เปนตน

• แบบจาลองสาหรบ Individual Fixed effect regression จงเปน

Y = β + β X + γ D2 + γ D3 + ⋯ + γ D퐼 + u

• เมอ Yit คอ อตราการตายจากอบตเหต (i = entity and t = time)

Xit คอ ภาษเบยร

훽 คอ คาสมประสทธ, (k=0,1)

uit คอ error term

DI คอ ตวแปรหน (binary dummies) มจานวนเทากบ i-1 entities

훾 คอ คาสมประสทธของ dummies

128

Fixed effects

Page 129: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• การประมาณสมการถดถอยทม Fixed effects ยงคงองกบหลกการของ OLS ทมตวแปรหนหลายตว

• แตในทางปฏบต การทจานวนหนวยตวอยาง (entities) มมากจะทาใหการประมวลผลมความยงยาก และอาจเกดปญหา Over-parameter

129

Fixed effects

Page 130: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

2. วธ Demean

วธนใชหลกการการ Transform ขอมล Y และ X ใหม เพอขจด Fixed

effect ออกไป ซงทาไดดงน

จากแบบจาลอง Individal Fixed effect regression

Y = β X + α + u

ขนแรก คานวณคาเฉลยของตวแปรทกตวสาหรบแตละหนวย เชนคาเฉลยแตละป ของ entity i เราจะได Y และ X

ขนสอง นาคาเฉลยไปลบออกจากคาจรง (entity-demeaned) ไดเปน

Y − Y ⇒ Y และ X − X ⇒ X

130

Fixed effects

Page 131: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• แบบจาลอง Fixed effect regression ใหมททาการ Demean แลว จะไดเปน

Y = β X + u

• เมอประมาณสมการขางตนดวยวธ OLS คา intercept ทไดจะมคาเขาใกล 0 นนคอ อทธพลของ fixed effect

ถกขจดออกไปแลว

เศรษฐมต I 751703 131

Fixed effects

Page 132: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

การใช Fixed effects regression กบตวอยางการตายจากอบตเหต

• ทาการศกษา 7 ป (ป 1982-1988) วธการ Differencing หรอวธ Before and After

ทาใหตองเสยขอมลตรงกลางไป 5 ป (ป 1983-1987) เนองจากตองเลอกใชเฉพาะขอมล

ของปแรกและปสดทาย

• แตวธการ Individual Fixed effects regression จะเปนวธทใชประโยชนจากขอมลทก

ป ดงนน จานวนคาสงเกตทงหมดจงเทากบ (48)(7)=336 คา

• โดยสมการทประมาณไดคอFR = −0.66BeerTax + StateFixedEffects

ผลของภาษเบยรทมตออตราการตายเปนลบ (เชนเดยวกบวธ Differencing)

คาสมประสทธทไดจากสองวธนไมเทากน เนองจากขอมลทใชในการประมวลผลตางกน

วธ Fixed effects regression ใหคา Standard error ตากวา

เศรษฐมต I 751703 132

Fixed effects

Page 133: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Time fixed effects Panel regression

• การศกษาขอมล Panel มกมการตงขอสงเกตวา ตวแปรตามอาจมการเปลยนแปลงไปตามระยะเวลา โดยเปนอทธพลมากจากตวแปรอสระทเปลยนแปลงไปตามเวลาแตมผลตอทกหนวยตวอยางเทาๆ กน จงเรยกผลนวา Time fixed effects

• เชน ใหอตราการตายจากอบตเหตบนทองถนนเปนตวแปรตาม ซงถกกระทบดวยตวแปรอสระทมการเปลยนแปลงตามเวลาและเปน unobserved variables เชน การพฒนาระบบความปลอดภยของยานพาหนะ ทาใหรถยนตมคณภาพดขน อตราการตายจากอบตเหตจงลดลงเมอเวลาผานไป

• โดย ณ ชวงเวลาเดยวกน การพฒนาระบบความปลอดภยของรถยนตนาจะเทาเทยมกนในทกรฐ

เศรษฐมต I 751703 133

Fixed effects

Page 134: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• ดงนน แบบจาลอง Individual and Time Fixed effect regression จงถกปรบปรงเปน

Y = β + β X + β Z + β S + u

โดย S คอ ตวแปรความปลอดภย ทเปลยนแปลงไปตามเวลา แตคงทสาหรบ

แตละรฐ

• ใชตวแปรหนเวลา (Time dummy: T) แทนตวแปรความปลอดภย ซงใชหลกการเดยวกนกบตวแปรหนของหนวยตวอยาง (Entity dummy) เรยกตวแปรหนเวลานวา Time fixed effects

Y = β + β X + γ D + γ D + ⋯ + γ D + 훿 T + ⋯ + 훿 T + u

โดย i=1,…,I , t=1,…,T

134

Fixed effects

Individual effect Time effect

Page 135: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• แบบจาลอง Individual and Time Fixed effect regression สามารถเขยนใหมไดเปน

Y = β X + α + λ + uโดยกาหนดให

oα เปนคา intercept ของแตละหนวยทศกษา (Entity fixed effects หรอIndividual fixed effects) และ

oλ เปนคา intercept ของแตชวงเวลา (Time fixed effects)

• การรวม Entity fixed effect และ Time fixed effect จะทาใหแบบจาลองกาจดความเอนเอยงอนเนองมาจากการละเลยตวแปรทไมสามารถสงเกตได

• วธการประมาณแบบจาลองทมทง Entity fixed effect และ Time fixed effect ในทางปฏบตทาไดโดยการประมาณ Demean แลวเพมตวแปรหนเวลาในแบบจาลอง

• ในกรณ Demean จะตองหาคาเฉลยของ entity ในแตละป Y และ X จากนน

Y − Y ⇒ Y และ X − X ⇒ X

Fixed effects

Page 136: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ตวอยางการใช Individual fixed effects และ Time fixed effects กบตวอยางการตายจากอบตเหตบนทองถนน

• เมอเพมตวแปรหนเวลาแลว สมการทประมาณไดคอ

FR = −0.64BeerTax + StateFixedEffects + TimeFixedEffects

136

Fixed effects

Page 137: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ขอสมมตของการใช Fixed effect regression

137

ขอสมมตทสาคญของการประมาณสมการถดถอยทม Fixed Effects มดงน

ขอสมมตท 1

ในแบบจาลองประชากร X และ Y มความสมพนธเชงเสน (linear in

parameters)Y = β X + β X + ⋯ + β X + α + u

ขอสมมตท 2

มตวอยางทเกดจากการสม (Random Sample) ในมตของภาคตดขวาง

ขอสมมตท 3

error term เปนอสระจาก x (zero unconditional mean)E u |X , α = 0

Fixed effects

Page 138: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

138

ขอสมมตท 4

ตวแปรอสระทเปลยนแปลงไปตามเวลาไมมความสมพนธเชงเสนกนอยาง

สมบรณ (no perfect multicollinearity) ระหวางกน

ขอสมมตท 5

Var u |X , α = Var u = σ สาหรบ t = 1,2,...,T

ขอสมมตท 6

Cov u , u |X , α = 0 สาหรบ t ≠ s

ขอสมมตท 7

u ~iidN 0, σ สาหรบ t ≠ s

Fixed effects

Page 139: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ตวอยางการศกษาผลของภาษเบยรตอการเสยชวตจากอบตเหตบนทองถนน

139

ตวแปรตาม: อตราการตายจากอบตเหตบนทองถนนตอประชากร 10,000 คน

Fixed effects

Page 140: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

เศรษฐมต I 751703 140

Fixed effects

Page 141: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Random Effect Model

• แนวคดหลกของ Random effects model คอ ความแตกตางระหวางหนวยตวอยาง (เชน รฐ) จะตอง random และไมมความสมพนธกบตวแปรอสระ (X) ทใสในแบบจาลอง

• Random effects model มลกษณะ ดงน

Y = 훽X + α + u + 휀

141

Within-entity error

Between-entity error

Random effects

Page 142: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• ประโยชนของ Random effects คอ เราสามารถประมาณผลของตวแปรทไมเปลยนแปลงตามเวลาแตมอทธพลตอ Y ได เชน เพศ เปนตน

• แตใน Fixed effects model อทธพลจากตวแปรเหลานทมตอ Y จะถกรวมอยใน intercept term และเมอประมาณแลวจะมคาเทากบ 0

142

Random effects

Page 143: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Fixed Effect หรอ Random Effect ?

• ใช Hausman test ในการตดสนวาจะใช fixed effect หรอ random effect

• แนวคดหลกของ Hausman test คอการทดสอบวา u (individual effect) มความสมพนธกบตวแปรอธบาย (regressor, X) หรอไม

• ถา individual effects มความสมพนธกบตวแปรอธบายในแบบจาลอง ->FE model is consistent และ RE model is inconsistent.

• ถา individual effects ไมมความสมพนธกบตวแปรอธบายในแบบจาลอง ->FE and RE models are consistent และ RE is efficient.

143

Page 144: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• กรณท individual effect และ regressors ไมมความสมพนธกน ทงแบบจาลอง

FE และ RE จะ consistent นนคอ คา 훽 ทประมาณไดจากทงสองแบบจาลองควรมคาใกลเคยงกน ไมควรแตกตางกน

• แตถาคาทประมาณไดจากสองแบบจาลองมความแตกตางกน แสดงวา RE is

inefficient. ดงนน ไมควรใช RE model

144

Fixed Effect หรอ Random Effect ?

Page 145: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Hausman test

• แนวคดของ Hausman test จงเกยวของกบ distance หรอความหางระหวางคา 훽 ทประมาณไดจากทงสองแบบจาลอง หรอ (훽 −훽 ) และ Covariance ระหวาง พารามเตอร 2 ตวน

• สมมตฐานของการทดสอบ คอ

สมมตฐานหลก (Null hypothesis)

H0 : No difference between estimators (ใช Random effect ได)

สมมตฐานรอง (Alternative hypothesis)

Ha : H0 is not true (ไมควรใช Random effect)

145

Page 146: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

• โดยมสถตทดสอบ คอ

푊 = (훽 −훽 ) Σ (훽 −훽 )~휒 (푘)

• ถา W มนยสาคญทางสถต ดงนน เราจะปฎเสธ H0 และเราไมควรใช RE model

146

Hausman test

Page 147: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Programming

• Rcode• Stata

Page 148: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Panel regressionlibrary(plm)#Step 1 Import Datadata=read.csv(file.choose(),head=TRUE)#Step 2 Convert file to be Panel datapanel <- pdata.frame(data,c("id","year"))#Step 3 Run Panel regression (Fixed effect)# 3.1 (First Difference)fd<- plm( y ~ x1 + x2, model = "fd", data=panel)summary(fd)# 3.2 (Fixed effect)fe <- plm( y ~ x1 + x2, model = "within", data=panel)summary(fe)# 3.3 (Random effect)re <- plm( y ~ x1 + x2, model = "random", data=panel)summary(re)# 3.4 (Pooling OLS ปกต)

pool <- plm( y ~ x1 + x2, model = "pool", data=panel)summary(pool) 148

Page 149: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R code: Hausman Test

# Hausman Test (Compare only Random and Fixed )phtest(fe, re)

149

ผลการทดสอบ

Hausman Testdata: y ~ x1 + x2chisq = 31.267, df = 2, p-value = 1.623e-07

alternative hypothesis: one model is inconsistent

จากผลการทดสอบ เราจะพบวา Hausman Test มนยสาคญทางสถต ดงนนเรา

ตองปฎเสธ H0 และยอมรบ Ha

H0 : No difference between estimators (ใช Random effect ได)

Ha : H0 is not true (ไมควรใช Random effect)

Page 150: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA

• สาหรบโปรแกรมตวนเปน ทนยมในการทา Panel อยางมากในปจจบนและมการทดสอบทคอนขางครบถวนกวา เมอเทยบกบ Eview ดงนน เราจงสามารถใชโปรแกรม STATA ในการประมาณการ Panel Regression

• ในบทท 5 นเราจะทาการประมาณดงน

5.1 การนาขอมลเขาและ set up ขอมล

5.2 การประมาณแบบจาลอง Fixed effects 5.2 การประมาณแบบจาลอง Random effects 5.4 Hausman Test

150

Page 151: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 1 นาขอมลเขา

151

Click

Page 152: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 1 นาขอมลเขา

152

1) จะปรากฏหนาตางลงขอมลออกมาคลายกบ Excel ให copy ขอมลจาก file excel ลงมาวางในน

2) Copy Paste ใหเลอก Treat first rows as variable name3) ขอมลจะปรากฎดงภาพ

Page 153: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 1 Set up ขอมลใหอยในรป Panel

153

Click

Page 154: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 1 Set up ขอมลใหอยในรป Panel

154

เลอก column ทแสดง idเลอก column ทแสดง Time(year)

Tick ความถขอมล

Page 155: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 1 นาขอมลเขา

155

เลอก

Click OK

Page 156: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

156

STATA: STEP 1 SET UP เสรจสน

Page 157: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 2 Run Fixed effects

157

Click

Click

Page 158: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 2 Run Fixed effects

158

ตวแปรตาม

Click

ตวแปรตน

1 1 2 2it i ity x x

OK

0 1 1 2 2it i ity x x

Page 159: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: Fixed effects results

159

Page 160: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: STEP 3 Run Random effectsทาเหมอน Fixed effects แตขนตอนสดทาย คอดงน

160

Clickตวแปรตาม

Click

ตวแปรตน

OK

0 1 1 2 2it i ity x x

Page 161: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: Random effects results

161***ในบางกรณผลออกไมหมด ใหนกศกษา click more

Page 162: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: Hausman Test (Stata Code)

162

xtreg y x1 x2, feestimates store fixedxtreg y x1 x2, rehausman random ., constant equations(1:1) df(1)

Command

Page 163: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: Hausman Test Result

163

Pvalue=1.000 , ยอมรบ H0

Page 164: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

เพมเตม Panel Unit root test

164

Page 165: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R-code : Check Unit root testrm(list=ls(all=TRUE))

library("plm")

#Step 1 Import Data

data=read.csv(file.choose(),head=TRUE)

#Step 2 Convert file to be Panel data

panel <- pdata.frame(data,c("id","year"))

#Step 3 Get each variable

y <- data.frame(split(panel$y, panel$id))

x1 <- data.frame(split(panel$x1, panel$id))

x2 <- data.frame(split(panel$x2, panel$id))

LLC <- purtest(x2,test = "hadri",exo ="intercept", lags = "AIC", pmax = 0)

LLC

165

# ตวอยางผลการประมาณ

Hadri Test (ex. var.: Individual Intercepts) (Heterosked. Consistent)data: yz = -0.1723, p-value = 0.5684alternative hypothesis: at least one series has a unit root

ยอมรบ H0 ดงนนตวแปร

Y ของเราเลยนง

Page 166: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: check unit root test

166

Click

Click

Page 167: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

STATA: check unit root test

167

Levin Lin and Chu Unit root test

ตวแปร

Tick

Ok

Page 168: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

ผลการทดสอบ Panel unit root test กรณ y

เศรษฐมต I 751703 168

ยอมรบ H0 ดงนนตวแปรของ

เราเลยไมนง

Page 169: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Assignment 5

1. Panel regression และ Time series regression เหมอนหรอแตกตางกนอยางไร

2. จงยกตวอยางปญหางานวจยทตองใชแบบจาลอง Panel regression3. จงอธบายความแตกตางระหวาง Fixed และ Random effects4. individual effect สมพนธกบตวแปร X ไดหรอไม ถาไมไดเราควรทา

อยางไร หรอถาไดเราจะประมาณ Panel regression ไดหรอไม

169

Page 170: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Assignment 5 Program

จงใชขอมลจาก ไฟล DATA5.csv 1) เชค Unit root ทกตวแปร

2) ประมาณแบบจาลอง Fixed effects3) ประมาณแบบจาลอง Random effects4) เราควรใชแบบจาลองใดเพอไปแปลผลการศกษาตอไป จงพสจน

170

Page 171: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

stochastic frontier Modelhttps://www.sciencedirect.com/science/article/pii/S0888613X15000493

The Stochastic frontier model (SFM) has proved very useful to assess technical efficiency of production units. The stochastic frontier production model for a cross-section of observations.History in brief Regression

Stochastic frontier model(Aigner et al. 1977)

Copula based Stochastic frontier model(Smith, 2008, Wiboonpongseet al.2015) )

Page 172: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Copula based stochastic frontier Model• Model structure and concept

( ) exp( )i ikY f X U V

ln ln , 1,...,i ik iiY X U V i I 2~ (0, )UU N

2~ (0, )VV N

Page 173: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

Copula based stochastic frontier Model• Technical Efficiency

exp( ) /exp( ) exp( )i ik i i ik i iTE X V U X V U

In the stochastic frontier production approach, the technical efficiency is either defined as a minimum set of inputs required to produce a given level of output or alternatively as the maximum output attainable using a given set of inputs (Farrell 1957).

TE takes the values between 0-1. The higher TE, the higher efficiency.

Page 174: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

## Required packageslibrary("frontier")

R Code

1. Install packages

Page 175: Econommetric - WordPress.com...Chapter 1 Regression with Time-Series Data: Stationary Variables Dr. WoraphonYamaka ... 12 0 20 40 60 80 100 y ... Regression with Time-Series Data:

R Code

2. Code :# example included in FRONTIER 4.1 (cross-section data)data(front41Data)attach(front41Data)# Cobb-Douglas production frontiercobbDouglas <- sfa( log(output)~log(capital)+log(labour),data=front41Data)summary(cobbDouglas)

Error Components Frontier (see Battese & Coelli 1992) Inefficiency decreases the endogenous variable (as in a production function)

final maximum likelihood estimatesEstimate Std. Error z value Pr(>|z|)

(Intercept) 0.561619 0.202617 2.7718 0.0055742 ** log(capital) 0.281102 0.047643 5.9001 3.632e-09 ***log(labour) 0.536480 0.045252 11.8555 < 2.2e-16 ***sigmaSq 0.217000 0.063909 3.3955 0.0006851 ***gamma 0.797207 0.136424 5.8436 5.109e-09 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1log likelihood value: -17.02722

cross-sectional datatotal number of observations = 60

mean efficiency: 0.7405678