Top Banner
Part1. 繪繪繪繪 繪繪繪繪繪繪繪繪繪繪 ssc install spmap ssc install shp2dta ssc install mif2dta
53

Part1. 繪製地圖 安裝繪製地圖所需程式

Feb 06, 2016

Download

Documents

waite

Part1. 繪製地圖 安裝繪製地圖所需程式. ssc install spmap ssc install shp2dta ssc install mif2dta. 讀取 CHN_adm1 地圖檔。創出 chinaprovince 以及 coord 兩個檔案. shp2dta using CHN_adm1, database (chinaprovince) coordinates(coord) genid(id) gencentroids(c). *打開 chinaprovince 檔案,刪除 Paracel Islands. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Part1. 繪製地圖 安裝繪製地圖所需程式

Part1.繪製地圖安裝繪製地圖所需程式

ssc install spmap ssc install shp2dtassc install mif2dta

Page 2: Part1. 繪製地圖 安裝繪製地圖所需程式

讀取 CHN_adm1地圖檔。創出chinaprovince以及 coord兩個

檔案shp2dta using CHN_adm1, database (chinaprovince) coordinates(coord) genid(id) gencentroids(c)

Page 3: Part1. 繪製地圖 安裝繪製地圖所需程式

*打開 chinaprovince檔案,刪除 Paracel Islands

Page 4: Part1. 繪製地圖 安裝繪製地圖所需程式
Page 5: Part1. 繪製地圖 安裝繪製地圖所需程式

把想顯示於地圖的 data放進 chinaprovince中

Page 6: Part1. 繪製地圖 安裝繪製地圖所需程式
Page 7: Part1. 繪製地圖 安裝繪製地圖所需程式

繪出 2007年中國 FDI分布圖spmap FDI_2007 using coord, id(id) clnumber(5)

Page 8: Part1. 繪製地圖 安裝繪製地圖所需程式

可點選 start graph editor編輯

Page 9: Part1. 繪製地圖 安裝繪製地圖所需程式

Part2.建立空間計量矩陣findit spmat

Page 10: Part1. 繪製地圖 安裝繪製地圖所需程式

點選第一個超連結

Page 11: Part1. 繪製地圖 安裝繪製地圖所需程式

點選 (click here to install)進行下載

Page 12: Part1. 繪製地圖 安裝繪製地圖所需程式

讀取 chinaprovince,並將 x_c 跟y_c改名

Page 13: Part1. 繪製地圖 安裝繪製地圖所需程式

改為 longitude 與 latitude

Page 14: Part1. 繪製地圖 安裝繪製地圖所需程式

生成距離矩陣spmat idistance idistance_province longitude latitude, id(id) dfunction(euclidean) normalize(row)

Page 15: Part1. 繪製地圖 安裝繪製地圖所需程式

生成 stata可讀之檔案idistance_province.spmat

spmat save idistance_province using idistance_province.spmat

(此時 stata資料夾出現idistance_province.spmat)

Page 16: Part1. 繪製地圖 安裝繪製地圖所需程式

將剛剛的idistance_province.spmat檔案轉為我們可閱讀的 txt檔spmat export idistance_province using idistance_province.txt

Page 17: Part1. 繪製地圖 安裝繪製地圖所需程式

此時 stata資料夾出現idistance_province.txt

Page 18: Part1. 繪製地圖 安裝繪製地圖所需程式

生成相鄰矩陣spmat contiguity contiguity_province using coord, id(id) normalize(row)

Page 19: Part1. 繪製地圖 安裝繪製地圖所需程式

生成 stata可讀之檔案spmat save contiguity_province using contiguity_province.spmat

Page 20: Part1. 繪製地圖 安裝繪製地圖所需程式

將剛剛的contiguity_province.spmat檔案轉為我們可閱讀的 txt檔spmat export contiguity_province using contiguity_province.txt

Page 21: Part1. 繪製地圖 安裝繪製地圖所需程式

此時 stata資料夾出現contiguity_province.txt

Page 22: Part1. 繪製地圖 安裝繪製地圖所需程式

Part.3 跑空間計量findit xsmle

Page 23: Part1. 繪製地圖 安裝繪製地圖所需程式

點選第一個超連結

Page 24: Part1. 繪製地圖 安裝繪製地圖所需程式

往下拉,點選 (click here to install)進行下載

Page 25: Part1. 繪製地圖 安裝繪製地圖所需程式

spmat use W using "idistance_province.spmat "(使用距離矩陣跑空間計量 )spmat use W using "contiguity_province.spmat"(使用相鄰矩陣跑空間計量 )

Page 26: Part1. 繪製地圖 安裝繪製地圖所需程式

告知 stata要跑 panel data,才可以跑空間計量

xtset id year

Page 27: Part1. 繪製地圖 安裝繪製地圖所需程式

開啟資料 data,公布年度 _上課用

xsmle FDI FT GDP WAGE OPEN CFDI , wmat(W) mode(sdm) re(其中第一個變數 stata會自動設定為 Y ,之後都是X , re為隨機效果模型, fe為固定效果模型。mode可選 sar 與 sdm)

Page 28: Part1. 繪製地圖 安裝繪製地圖所需程式

CFDI .0927104 .0070784 13.10 0.000 .078837 .1065837

OPEN 52617.83 15357.92 3.43 0.001 22516.87 82718.8

WAGE -.8204718 .4860468 -1.69 0.091 -1.773106 .1321623

GDP .6832036 .5361676 1.27 0.203 -.3676656 1.734073

FT 94.43746 84.33592 1.12 0.263 -70.85791 259.7328

Direct

sigma_e 1.43e+07 2820431 5.08 0.000 8799255 1.99e+07

lgt_theta -2.983231 .2074382 -14.38 0.000 -3.389802 -2.57666

Variance

rho .1448937 .3745166 0.39 0.699 -.5891454 .8789328

Spatial

CFDI -.0250511 .059445 -0.42 0.673 -.1415612 .091459

OPEN 7278.992 46083.16 0.16 0.874 -83042.34 97600.32

WAGE -1.156691 1.337933 -0.86 0.387 -3.778992 1.465609

GDP 2.992128 3.799625 0.79 0.431 -4.455 10.43926

FT 166.7804 605.3808 0.28 0.783 -1019.744 1353.305

Wx

_cons 34602.23 25657.5 1.35 0.177 -15685.55 84890.02

CFDI .0925311 .0064227 14.41 0.000 .0799428 .1051194

OPEN 52942.06 14912.52 3.55 0.000 23714.05 82170.06

WAGE -.8209484 .457982 -1.79 0.073 -1.718577 .0766798

GDP .5898734 .4588287 1.29 0.199 -.3094144 1.489161

FT 95.36754 91.50272 1.04 0.297 -83.9745 274.7096

Main

FDI Coef. Std. Err. z P>|z| [95% Conf. Interval]

Log-likelihood = -992.2360

Page 29: Part1. 繪製地圖 安裝繪製地圖所需程式

CFDI .0884814 .0062748 14.10 0.000 .076183 .1007798

OPEN 31394.1 12006.58 2.61 0.009 7861.647 54926.56

WAGE -.6336338 .4152306 -1.53 0.127 -1.447471 .1802032

GDP .4246668 .5147828 0.82 0.409 -.5842889 1.433623

FT 69.75591 71.38884 0.98 0.329 -70.16364 209.6755

Direct

sigma2_e 8724978 1279760 6.82 0.000 6216695 1.12e+07

Variance

rho -.0728405 .4367999 -0.17 0.868 -.9289525 .7832716

Spatial

CFDI -.0074108 .0547492 -0.14 0.892 -.1147173 .0998957

OPEN 11053.53 40357.06 0.27 0.784 -68044.86 90151.92

WAGE -1.446171 1.164901 -1.24 0.214 -3.729335 .8369927

GDP 3.910964 3.290304 1.19 0.235 -2.537914 10.35984

FT -37.54984 494.9329 -0.08 0.940 -1007.6 932.5008

Wx

CFDI .0881605 .0050674 17.40 0.000 .0782286 .0980925

OPEN 31436 12066.89 2.61 0.009 7785.338 55086.66

WAGE -.6528307 .388018 -1.68 0.092 -1.413332 .1076707

GDP .3990044 .3815596 1.05 0.296 -.3488387 1.146847

FT 68.49903 73.67781 0.93 0.353 -75.90682 212.9049

Main

FDI Coef. Std. Err. z P>|z| [95% Conf. Interval]

Log-likelihood = -875.1221

Page 30: Part1. 繪製地圖 安裝繪製地圖所需程式

Sem模型xsmle FDI FT GDP WAGE OPEN CFDI , ematrix(W) mode(sem) re

Page 31: Part1. 繪製地圖 安裝繪製地圖所需程式

將 W 改為相鄰矩陣spmat use W using "contiguity_province.spmat" ,replace

Page 32: Part1. 繪製地圖 安裝繪製地圖所需程式

重複剛剛的步驟xsmle FDI FT GDP WAGE OPEN CFDI , wmat(W) mode(sdm) re

Page 33: Part1. 繪製地圖 安裝繪製地圖所需程式

WAGE -.8280938 .2907724 -2.85 0.004 -1.397997 -.2581904

GDP .4329611 .4719747 0.92 0.359 -.4920923 1.358015

FT 115.4091 73.59384 1.57 0.117 -28.83218 259.6504

Direct

sigma_e 1.19e+07 2355401 5.05 0.000 7280572 1.65e+07

lgt_theta -2.959432 .2054211 -14.41 0.000 -3.36205 -2.556814

Variance

rho .3649768 .1315159 2.78 0.006 .1072104 .6227432

Spatial

CFDI -.0460164 .0178403 -2.58 0.010 -.0809827 -.0110501

OPEN 1975.193 24510.05 0.08 0.936 -46063.61 50014

WAGE -.2951333 .4505019 -0.66 0.512 -1.178101 .5878342

GDP 1.385675 .9683436 1.43 0.152 -.512244 3.283593

FT 315.4662 163.4135 1.93 0.054 -4.81836 635.7507

Wx

_cons 20322.98 9976.056 2.04 0.042 770.2701 39875.69

CFDI .0953237 .0064428 14.80 0.000 .082696 .1079513

OPEN 51826.03 13089.78 3.96 0.000 26170.53 77481.54

WAGE -.7870454 .2761907 -2.85 0.004 -1.328369 -.2457217

GDP .2640631 .4217304 0.63 0.531 -.5625133 1.09064

FT 83.52678 79.32219 1.05 0.292 -71.94186 238.9954

Main

FDI Coef. Std. Err. z P>|z| [95% Conf. Interval]

Log-likelihood = -984.3404

Page 34: Part1. 繪製地圖 安裝繪製地圖所需程式

CFDI .0892304 .0050846 17.55 0.000 .0792647 .0991961

OPEN 33359.6 11465.38 2.91 0.004 10887.86 55831.34

WAGE -.5767623 .2488954 -2.32 0.020 -1.064588 -.0889363

GDP .3193532 .4195972 0.76 0.447 -.5030423 1.141749

FT 93.11735 58.38873 1.59 0.111 -21.32246 207.5572

Direct

sigma2_e 7293312 1084031 6.73 0.000 5168651 9417974

Variance

rho .3369109 .1406159 2.40 0.017 .0613088 .612513

Spatial

CFDI -.0385547 .0164329 -2.35 0.019 -.0707626 -.0063468

OPEN -12976.88 21164.02 -0.61 0.540 -54457.6 28503.85

WAGE -.333219 .3885812 -0.86 0.391 -1.094824 .4283861

GDP 1.470184 .8387266 1.75 0.080 -.1736897 3.114058

FT 239.7663 130.445 1.84 0.066 -15.90124 495.4339

Wx

CFDI .0895429 .0050829 17.62 0.000 .0795806 .0995051

OPEN 33836.74 10791.88 3.14 0.002 12685.05 54988.42

WAGE -.5378699 .2190107 -2.46 0.014 -.967123 -.1086169

GDP .1562309 .3554739 0.44 0.660 -.5404851 .8529469

FT 66.30069 63.39159 1.05 0.296 -57.94453 190.5459

Main

FDI Coef. Std. Err. z P>|z| [95% Conf. Interval]

Log-likelihood = -868.0404

Page 35: Part1. 繪製地圖 安裝繪製地圖所需程式

檢定使用 sdm模型或是 sar模型

如果拒絕 H0,則使用 sdm

test [Wx]FT=[Wx]GDP=[Wx]WAGE=[Wx]OPEN=[Wx]CFDI=0

Page 36: Part1. 繪製地圖 安裝繪製地圖所需程式

拒絕 H0,使用 sdm

Prob > chi2 = 0.0186

chi2( 5) = 13.57

( 5) [Wx]FT = 0

( 4) [Wx]FT - [Wx]CFDI = 0

( 3) [Wx]FT - [Wx]OPEN = 0

( 2) [Wx]FT - [Wx]WAGE = 0

( 1) [Wx]FT - [Wx]GDP = 0

. test [Wx]FT=[Wx]GDP=[Wx]WAGE=[Wx]OPEN=[Wx]CFDI=0

Page 37: Part1. 繪製地圖 安裝繪製地圖所需程式

檢定使用 sdm模型或是 sem模型

如果拒絕 H0,則使用 sdmtestnl ([Wx]FT = -[Spatial]rho*[Main]FT) ([Wx]GDP = -[Spatial]rho*[Main]GDP) ([Wx]WAGE = -[Spatial]rho*[Main]WAGE) ([Wx]OPEN = -[Spatial]rho*[Main]OPEN) ([Wx]CFDI = -[Spatial]rho*[Main]CFDI)

Page 38: Part1. 繪製地圖 安裝繪製地圖所需程式

拒絕 H0,使用 sdm

Prob > chi2 = 0.0431

chi2(5) = 11.45

(5) [Wx]CFDI = -[Spatial]rho*[Main]CFDI

(4) [Wx]OPEN = -[Spatial]rho*[Main]OPEN

(3) [Wx]WAGE = -[Spatial]rho*[Main]WAGE

(2) [Wx]GDP = -[Spatial]rho*[Main]GDP

(1) [Wx]FT = -[Spatial]rho*[Main]FT

> OPEN = -[Spatial]rho*[Main]OPEN) ([Wx]CFDI = -[Spatial]rho*[Main]CFDI)

. testnl ([Wx]FT = -[Spatial]rho*[Main]FT) ([Wx]GDP = -[Spatial]rho*[Main]GDP) ([Wx]WAGE = -[Spatial]rho*[Main]WAGE) ([Wx]

Page 39: Part1. 繪製地圖 安裝繪製地圖所需程式

使用 hausmam test檢定固定效果模型或隨機效果模型

Page 40: Part1. 繪製地圖 安裝繪製地圖所需程式

先跑隨機效果模型,並儲存結果

xsmle FDI FT GDP WAGE OPEN CFDI , wmat(W) mode(sdm) re

estimates store re

Page 41: Part1. 繪製地圖 安裝繪製地圖所需程式

再先跑固定效果模型,並且儲存結果

xsmle FDI FT GDP WAGE OPEN CFDI , wmat(W) mode(sdm) fe

estimates store fe

Page 42: Part1. 繪製地圖 安裝繪製地圖所需程式

檢定使用固定效果模型或隨機效果模型

hausman re fe

Page 43: Part1. 繪製地圖 安裝繪製地圖所需程式

拒絕 H0,使用固定效果模型

.

Prob>chi2 = 0.0523

= 5.90

chi2(2) = (b-B)'[(V_b-V_B)^(-1)](b-B)

Test: Ho: difference in coefficients not systematic

B = inconsistent under Ha, efficient under Ho; obtained from xsmle

b = consistent under Ho and Ha; obtained from xsmle

CFDI .0953237 .0895429 .0057808 .003959

OPEN 51826.03 33836.74 17989.3 7407.956

WAGE -.7870454 -.5378699 -.2491755 .1682724

GDP .2640631 .1562309 .1078323 .2269248

FT 83.52678 66.30069 17.22609 47.68141

re fe Difference S.E.

(b) (B) (b-B) sqrt(diag(V_b-V_B))

Coefficients

Page 44: Part1. 繪製地圖 安裝繪製地圖所需程式

Part4. Moran’s I

findit spatwmat

Page 45: Part1. 繪製地圖 安裝繪製地圖所需程式

點選第二個連結

Page 46: Part1. 繪製地圖 安裝繪製地圖所需程式

點選 (click here to install)進行下載

Page 47: Part1. 繪製地圖 安裝繪製地圖所需程式

讀取 chinaprovince

spatwmat, name(Chinaweights) xcoord(longitude) ycoord(latitude) band(0 8)

Page 48: Part1. 繪製地圖 安裝繪製地圖所需程式

You are advised to extend the distance band

Beware! 2 locations have no neighbors

Smallest maximum distance: 24.06

Largest minimum distance: 9.86

Maximum distance: 43.1

3rd quartile distance: 19.4

Median distance: 13.2

1st quartile distance: 8.6

Minimum distance: 0.7

Friction parameter: 1

Distance band: 0 < d <= 8

Dimension: 31x31

1. Inverse distance weights matrix Chinaweights

The following matrix has been created:

. spatwmat, name(Chinaweights) xcoord(longitude) ycoord(latitude) band(0 8)

Page 49: Part1. 繪製地圖 安裝繪製地圖所需程式

下載繪製Moran’s I工具findit splagvar

Page 50: Part1. 繪製地圖 安裝繪製地圖所需程式

點選第一個連結

Page 51: Part1. 繪製地圖 安裝繪製地圖所需程式

點選 (click here to install)進行下載

Page 52: Part1. 繪製地圖 安裝繪製地圖所需程式

讀取檔案moran_FDI

splagvar FDI_2007, wname(Chinaweights) wfrom(Stata) moran(FDI_2007) plot(FDI_2007)

Page 53: Part1. 繪製地圖 安裝繪製地圖所需程式