文档库 最新最全的文档下载
当前位置:文档库 › 用STATA做空间计量

用STATA做空间计量

用STATA做空间计量
用STATA做空间计量

How can I calculate Moran's I in Stata?

Note: The commands shown in this page are user-written Stata commands that must be downloaded. To install the package of spatial analysis tools, type findit spatgsa in the command window.

Moran's I is a measure of spatial autocorrelation--how related the values of a variable are based on the locations where they were measured. Using a set of user-written Stata commands, we can calculate Moran's I in Stata. We will be using the spatwmat command to generate a matrix of weights based on the locations in our data and the spatgsa command to calculate Moran's I or other spatial autocorrelation measures.

Let's look at an example. Our dataset, ozone, contains ozone measurements from thirty-two locations in the Los Angeles area aggregated over one month. The dataset includes the station number (station), the latitude and longitude of the station (lat and lon), and the average of the highest eight hour daily averages (av8top). This data, and other spatial datasets, can be downloaded from the University of Illinois's Spatial Analysis Lab. We can look at a summary of our location variables to see the range of locations under consideration.

use https://www.wendangku.net/doc/a13061397.html,/stat/stata/faq/ozone.dta, clear

summarize lat lon

Variable | Obs Mean Std. Dev. Min Max

-------------+--------------------------------------------------------

lat | 32 34.0146 .2228168 33.6275 34.69012

lon | 32 -117.7078 .5683853 -118.5347 -116.2339

Based on the minimum and maximum values of these variables, we can calculate the greatest Euclidean distance we might measure between two points in our dataset.

display sqrt((34.69012 - 33.6275)^2 + (-116.2339 - -118.5347)^2)

2.5343326

Knowing this maximum distance between two points in our data, we can generate a matrix based on the distances between points. In the spatwmat command, we name the weights matrix to be generated, indicate which of our variables are the x- and y-coordinate variables, and provide a range of distance values that are of interest in the band option. All of the distances are of interest in this example, so we create a band with an upper bound greater than our largest possible distance. If we did not care about distances greater than 2, we could indicate this in the band option.

spatwmat, name(ozoneweights) xcoord(lon) ycoord(lat) band(0 3)

The following matrix has been created:

1. Inverse distance weights matrix ozoneweights

Dimension: 32x32

Distance band: 0 < d <= 3

Friction parameter: 1

Minimum distance: 0.1

1st quartile distance: 0.4

Median distance: 0.6

3rd quartile distance: 1.0

Maximum distance: 2.4

Largest minimum distance: 0.50

Smallest maximum distance: 1.23

As described in the output, the command above generated a matrix with 32 rows and 32 columns because our data includes 32 locations. Each off-diagonal entry [i, j] in the matrix is equal to 1/(distance between point i and point j). Thus, the matrix entries for pairs of points that are close together are higher than for pairs of points that are far apart. If you wish to look at the matrix, you can display it with the matrix list command. With our matrix of weights, we can now calculate Moran's I.

spatgsa av8top, weights(ozoneweights) moran

Measures of global spatial autocorrelation

Weights matrix

--------------------------------------------------------------

Name: ozoneweights

Type: Distance-based (inverse distance)

Distance band: 0.0 < d <= 3.0

Row-standardized: No

--------------------------------------------------------------

Moran's I

--------------------------------------------------------------

Variables | I E(I) sd(I) z p-value*

--------------------+-----------------------------------------

av8top | 0.248 -0.032 0.036 7.679 0.000

--------------------------------------------------------------

*1-tail test

Based on these results, we can reject the null hypothesis that there is zero spatial autocorrelation present in the variable av8top at alpha = .05.

Variations

Binary Matrix: If there exists some threshold distance d such that pairs with distances less than d

are neighbors and pairs with distances greater than d are not, you can create a binary neighbors matrix with the spatwmat command (indicating bin and setting band to have an upper bound of d) and use this weights matrix for calculating Moran's I. We could do this for d = .75:

spatwmat, name(ozoneweights) xcoord(lon) ycoord(lat) band(0 .75) bin

The following matrix has been created:

1. Distance-based binary weights matrix ozoneweights

Dimension: 32x32

Distance band: 0 < d <= .75

Friction parameter: 1

Minimum distance: 0.1

1st quartile distance: 0.4

Median distance: 0.6

3rd quartile distance: 1.0

Maximum distance: 2.4

Largest minimum distance: 0.50

Smallest maximum distance: 1.23

spatgsa av8top, weights(ozoneweights) moran

Measures of global spatial autocorrelation

Weights matrix

--------------------------------------------------------------

Name: ozoneweights

Type: Distance-based (binary)

Distance band: 0.0 < d <= 0.75

Row-standardized: No

--------------------------------------------------------------

Moran's I

--------------------------------------------------------------

Variables | I E(I) sd(I) z p-value*

--------------------+-----------------------------------------

av8top | 0.188 -0.032 0.033 6.762 0.000

--------------------------------------------------------------

*1-tail test

In this example, the binary formulation of distance yields a similar result. We can reject the null hypothesis that there is zero spatial autocorrelation present in the variable av8top at alpha = .05.

Using an existing matrix: If you have calculated a weights matrix according to some other metric than those available in spatwmat and wish to use it in calculating Moran's I, spatwmat allows you to read in a Stata dataset of the required dimensions and format it as a distance matrix that can be used by spatgsa. If altweights.dta is a dataset with 32 columns and 32 rows, it could be converted to a weighted matrix aweights to be used in spatgsa analyzing av8top:

spatwmat using "C:\altweights.dta", name(aweights)

How do I generate a variogram for spatial data in Stata?

When analyzing geospatial data, describing the spatial pattern of a measured variable is of great importance. User written Stata commands allow you to explore such patterns. This page will use the variog and variog2 command. To install this, type findit variog in your command window.

The variog command allows you to calculate and graph a variogram for regularly spaced one-dimensional data. The variog2 command allows you to calculate and graph a variogram for two-dimensional data without constraints on spacing. In both cases, the variogram illustrates how differences in a measured variable Z vary as the distances between the points at which Z is measured increase.

Let's look at an example. Our dataset contains ozone measurements from thirty-two locations in the Los Angeles area aggregated over one month. The dataset includes the station number (station), the latitude and longitude of the station (lat and lon), and the average of the highest eight hour daily averages (av8top). This data, and other spatial datasets, can be downloaded from the GeoDa Center for Geospatial Analysis and Computation.

use https://www.wendangku.net/doc/a13061397.html,/stat/stata/faq/ozone, clear

clist in 1/5

station av8top lat lon

1. 60 7.225806 34.13583 -117.9236

2. 69 5.899194 34.17611 -118.3153

3. 72

4.052885 33.82361 -118.1875

4. 74 7.181452 34.19944 -118.5347

5. 75

6.076613 34.06694 -11

7.7514

For the sake of an example, let's imagine that instead of specific latitude and longitude locations, the stations are evenly spaced along a single latitude. If we assume the observations are in the order in which the stations appear, we can use the variog command. In the command, we indicate the measured outcome and we will opt for the calculated values to be listed. By default, a plot of the semi-variogram will be generated.

variog av8top, list

+----------------------------------+

| Lag Semi-variance # of pairs |

|----------------------------------|

| 1 2.328506 31 |

| 2 2.615086 30 |

| 3 2.629862 29 |

| 4 2.983584 28 |

| 5 3.415026 27 |

|----------------------------------|

| 6 2.923007 26 |

| 7 4.104437 25 |

| 8 3.378503 24 |

| 9 3.531528 23 |

| 10 4.49281 22 |

|----------------------------------|

| 11 5.22965 21 |

| 12 6.657857 20 |

| 13 6.5462 19 |

| 14 6.126221 18 |

| 15 6.556983 17 |

|----------------------------------|

| 16 6.451519 16 |

+----------------------------------+

Next, let's generate a variogram using the latitude and longitude of the stations. For this, we will use the variog2 command. While the lag distance in variog was assumed to be the distance between each evenly spaced observation, variog2 requires the user to specify the lag distance. Let's look at a summary of our coordinates to get a sense of the distances existing in our data.

summarize lat lon

Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------

lat | 32 34.0146 .2228168 33.6275 34.69012

lon | 32 -117.7078 .5683853 -118.5347 -116.2339 Based on this, we can calculate the maximum possible distance we might see in our data.

dis sqrt((33.6275 - 34.69012)^2 + (-118.5347 - -116.2339)^2)

2.5343326

As a starting point, we can choose a lag distance of .1 and we can examine distances up to 12 lags apart. We want to choose a lag distance that yields enough pairs in each lag to generate a variance that we trust. We might aim to have at least 15 pairs in each lag.

variog2 av8top lat lon, width(.1) lags(12) list

+----------------------------------+

| Lag Semi-variance # of pairs |

|----------------------------------|

| 1 4.729442 6 |

| 2 1.8984963 31 |

| 3 1.3789778 41 |

| 4 2.7462469 50 |

| 5 4.3899238 49 |

|----------------------------------|

| 6 4.1974818 43 |

| 7 5.2652506 48 |

| 8 7.3351494 41 |

| 9 6.8823236 36 |

| 10 8.0089961 29 |

|----------------------------------|

| 11 6.6957223 29 |

| 12 7.1360346 23 |

+----------------------------------+

We can see that our first lag contains only 6 pairs. We might increase the size of our lags and look at fewer of them.

variog2 av8top lat lon, width(.15) lags(10) list

+----------------------------------+

| Lag Semi-variance # of pairs |

|----------------------------------|

| 1 1.8485044 21 |

| 2 1.8412199 57 |

| 3 3.1204523 74 |

| 4 4.4411303 68 |

| 5 5.8693088 70 |

|----------------------------------|

| 6 7.0979125 55 |

| 7 7.8960334 44 |

| 8 6.5713557 37 |

| 9 4.0710902 23 |

| 10 3.3176015 16 |

+----------------------------------+

In the output, we can see lag distances up to 10*.15 = 1.5, the number of pairs that are this far apart in the dataset, and the semi-variance. As we can see from the plot, the semi-variance increases until the lag distance exceeds .15*7 = 1.05.

《计量经济学》第三版例题stata解答

第二章 例2.1.1(p24) (1)表2.1.2中E(Y|X=800)即条件均值的求法,将数据直接复制到stata 中。 程序: sum y if x==800 程序: 程序: (2)图2.1.1的做法: 程序: twoway(scatter y x )(lfit y x ),title("不同可支配收入水平组家庭消费支出的条件分布图")xtitle("每月可支配收入(元)")ytitle("每月消费支出(元)")xtick(500(500)4000)ytick(0(500)3500)

例2.3.1(p37) 将数据直接复制到stata 中 程序: (1) total xiyi return list scalars: r(skip) = 0 r(first) = 1 r(k_term) = 0 r(k_operator) = 0 r(k) = 0 r(k_level) = 0 r(output) = 1 r(b) = 4974750 r(se) = 1507820.761894463 g a=r(b) in 1 total xi2 xiyi 4974750 1507821 1563822 8385678 Total Std. Err. [95% Conf. Interval] Scatter 表示散点图选项, lfit 表示回归线,title 表示 题目,xtick 表示刻度,(500 (500)4000)分别表示起 始刻度,中间数表示以单 位刻度,4000表示最后的 刻度。要注意的是命令中 的符号都要用英文字符, 否则命令无效。

return list g b=r(b) in 1 di a/b .67 (2) mean Yi gen m=r(b) in 1 mean Xi g n=r(b) in 1 di m-n*0.67 142.4 由此得到回归方程:Y=142.4+0.67Xi 例2.6.2(p53) 程序:(1)回归 reg y x

伍德里奇---计量经济学第6章部分计算机习题详解(STATA)

班级:金融学×××班姓名:××学号:×××××××C6.9 NBASAL.RAW points=β0+β1exper+β2exper2+β3age+β4coll+u 解:(ⅰ)按照通常的格式报告结果。 由上图可知:points=35.22+2.364exper?0.077exper2?1.074age?1.286coll 6.9870.4050.02350.295 (0.451) n=269,R2=0.1412,R2=0.1282。 (ⅱ)保持大学打球年数和年龄不变,从加盟的第几个年份开始,在NBA打球的经历实际上将降低每场得分?这讲得通吗? 由上述估计方程可知,转折点是exper的系数与exper2系数的两倍之比:exper?= β12β2= 2.364[2×?0.077]=15.35,即从加盟的第15个到第16个年份之间,球员在NBA打球的经历实际上将降低每场得分。实际上,在模型所用的数据中,269名球员中只有2位的打球年数超过了15年,数据代表性不大,所以这个结果讲不通。 (ⅲ)为什么coll具有负系数,而且统计显著? 一般情况下,NBA运动员的球员都会在读完大学之前被选拔出,甚至从高中选出,所以这些球员在大学打球的时间少,但每场得分却很高,所以coll具有负系数。同时,coll的t统计量为-2.85,所以coll统计显著。 (ⅳ)有必要在方程中增加age的二次项吗?控制exper和coll之后,这对年龄效应意味着什么?

增加age的二次项后,原估计模型变成: points=73.59+2.864exper?0.128exper2?3.984age+0.054age2?1.313coll 35.930.610.05 2.690.05 (0.45) n=269,R2=0.1451,R2=0.1288。 由方程可知:age的t统计量为?1.48,age2的t统计量为1.09,所以age和age的二次项统计都不显著,而当不增加age2时,age的t统计量为?3.64,统计显著,因此完全没有必要在方程中增加age的二次项。当控制了exper和coll之后,年龄对points的负效应将会增大。 (ⅴ)现在将log?(wage)对points,exper,exper2,age和coll回归。以通常的格式报告结论。 所以,log wage=6.78+0.078points+0.218exper?0.0071exper2?0.048age?0.040coll 0.850.0070.0500.00280.035 (0.053) n=269,R2=0.4878,R2=0.4781。 (ⅵ)在第(ⅴ)部分的回归中检验age和coll是否联合显著。一旦控制了生产力和资历,这对考察年龄和受教育程度是否对工资具有单独影响这个问题有何含义?

运用Stata做计量经济学

运用Stata做计量经济学 运用Stata建模的7步骤: 1、准备工作;目录、日志、读入数据、熟悉数据、时间变量、more、……; 2、探索数据:数据变换、描述统计量、相关系数、趋势图、散点图、……; 3、建立模型:regress、经济理论检验、实际经济问题要求、统计学检验、计量经济学检验:R2,T,t,残差; 4、诊断模型:异方差、序列相关、多重共线性、随机解释变量问题、……; 5、修正模型:WLS、GLS、工具变量法(ivregress),……; 6、应用模型:置信区间、预测、结构分析、边际分析、弹性分析、常用模型回归系数的意义、……; 7、整理:关闭日志、生成do文件备用 1、准备工作 让STATA处于初始状态,清除所有使用过的痕迹clear 指明版本号version11 设定并进入工作文件夹:cd D:\ (设定路径,将数据、程序和输出结果文件均存入该文件夹) 关闭以前的日志capture log close 建立日志:log using , replace 设定内存:set mem 20m

关闭more:set more off 读入数据:use .dta, clear 认识变量:describe 建立时间变量:tsset 2、用描述统计方法探索数据特征 必要的数据转换:gen、replace、……; 描述统计量:summarize, detail 相关系数矩阵:corr/pwcorr 散点图和拟合直线图:scatter y x || lfit y x 矩阵散点图:graph matrix y x1 x2 x3,half 线性趋势图:line y x 3、建立模型 OLS建立模型:regress y x1 x2 x3; 由方差分析表并用F和R2检验模型整体显著性; 依据p值对各系数进行t检验,一次只能剔出一个最不显著的变量,直到不包含不显著的变量; 估计参数,判别变量的相对重要性; 构造和估计约束模型,用以检验经济理论

计量经济学常用方法及应用-经济管理学院

计量经济学专题及应用 【授课计划:计划讲8个专题。主要是对计量经济学中5块常用的方法进行总结性和归纳性的介绍,侧重于讲在实际经济研究和实证分析中碰到相应问题时,计量经济方法上应当怎样处理,为什么要这样处理,如何处理,并结合STATA 讲应用例子。此外,1次专题介绍STATA的基础功能,1次专题系统梳理计量经济学的基础理论,还有1次专题结合实际研究例子,介绍一手数据搜集的调查设计和组织。通过上述课程,使学生能够在已经接受过基本理论和方法训练的基础上,更好地理解计量经济学的内容,并培养和提高开展实证研究的能力】 1、STATA简介及简单应用 介绍目前国内外最流行的计量经济分析软件STATA的基本功能和用法,通过简单例子介绍STATA在数据清理和管理、描述性统计分析、回归分析等方法的用法。同时插入EXCEL在处理数据方面的一些功能和应用。上午讲课,下午习题课。 2、计量经济分析基础 对计量经济学的基础理论进行总结性和归纳性的回顾、输理和介绍,重点讲假设检验和回归的道理,以及回归诊断。上午讲课,下午习题课。 3、项目评估与政策分析应用 系统介绍计量经济学在项目评估和政策分析上的方法和应用,特别介绍虚拟变量模型的建立及其在政策分析和项目评估研究中的应用。上午讲课,下午习题课。 4、经济学中的内生性问题及相关计量经济方法 总结和介绍计量经济学中内生性问题在经济研究中的涵义和问题,内生性问题产生的主要原因,对计量估计结果的影响,内生性问题的处理方法(工具变量和两阶段估计等)和应用例子。上午讲课,下午习题课。 5、微观个体行为的计量经济分析方法 总结和介绍分析微观个体行为的属性和受限因变量模型(Probit, Logit, Tobit, Heckman, Mlogit, Clogit等)等常用微观计量经济方法,包括模型内涵和适用范

计量经济学与stata——第一章

第一章引言 目录 1回归的本质 (1) 2计量经济学的一些基本概念和术语 (3) 2.1 统计关系与确定性关系 (3) 2.2 回归关系、相关关系与因果关系 (4) 2.3 术语与符号 (4) 2.4 数据类型 (4) 2.5 计量经济学的估计框架 (5) 2.6 经典计量经济学的方法论 (5) 3Stata简单介绍 (8) 4第一章附录: (8) 4.1 诺贝尔经济学奖与计量经济学 (8) 4.2 相关数学基础 (14) 4.3 本章相关数学证明 (19)

1 回归的本质 计量经济学的一般模型: 2(,)[]0[]y F X E E βεεεεσ′=+==Ω 回归是计量经济学的核心,理解回归的本质,对于掌握计量经济的理论与方法至关重要。回归的本质用语言来描述其实很简单,就是: 对于一组随机变量y 和X ,如果y 和X 存在特定的关系,为分析y 和X 之间的相互影响,或用X 去预测y ,需要知道y 和X 的模型形式以及模型中参数β的值,但是,由于—— 1、正确的模型形式(,)y F X β=未知,只能尽可能去逼近它(注:这涉及经济理论模型及模型设定的问题)。 2、即使假定模型的形式(,)y F X β=(不包括β)已被确定,也不可能穷尽随机变量和y X 的所有取值(即总体),来得到真实的β。 基于这两点,真实的模型形式(,)F X β和β无法得到,只能利用估计方法和 样本数据去尽可能得到与真实(,)F X β和β偏差或者误差最小的?(,)F X β和?β,即 2??min [((,))]E y F X β? (1) 使得(1)成立的?(,)F X β即是对于y X 的条件数学期望: ??(,)[/]F X E y X β= 注:从参数估计的角度来说,对于不同的估计方法,比如OLS (最小二乘估计法)、MLE (最大似然估计法)、GMM (矩估计或广义矩估计法),最小化均方误差的表述不尽相同,但本质是一样的。 理解回归的例子:凯恩斯消费函数、OLS 、一元线性回归(双变量回归) 凯恩斯消费函数是一个典型的一元线性回归模型,根据凯恩斯的经济理论,消费和收入存在密切的联系,如果用表示消费,Y 表示收入,则最简单与最常见的凯恩斯消费函数C 理论模型可表示为: C Y αβ=+ (2) 函数满足以下条件:

斯托克,沃森计量经济学第四章实证练习stata操作及答案

E4.1 E4.2 E4.3 E4.4

E4.1 VARIABLES ahe age 0.605 (0.0245) Constant 1.082 (0.688) Observations 7,711 R-squared 0.029 Robust standard errors in parentheses *** p<0.01, ** p<0.05, * p<0.1 1. ① 截距估计值estimated intercept: 1.082 ② 斜率估计值estimated slope: 0.605 回归方程:ahe= 1.082+0.605*age ③ 当工人年长 1 岁,平均每小时工资增加0.605 美元。 2. Bob: 0.605*26+1.082=16.812 (美元) Alexis: 0.605*30+1.082=19.232 (美元) 答:预测Bob 的收入为每小时16.812美元,Alexis为19.232 美元。 3. 年龄不能解释不同个体收入变化的大部分。因为R-squared 反映了因变量的 全部变化能通过回归关系被自变量充分解释的比例,而分析得R-squared 的值为0.029,解释度低,说明年龄不能解释不同个体收入变化的大部分

E4.1 (0.0449) Observations 463 R-squared 0.036 Robust standard errors in parentheses *** p<0.01, ** p<0.05, * p<0.1 ① 截距估计值: 3.998 斜率估计值: 0.133 回归方程: Course_Eval=3.998+0.133*beauty lave_esruo 0a u ty a e 1. 答:两者看上去有微弱的正相关关系 2. VARIABLES course eval beauty Constant 0.133 (0.0550) 3.998

-第2章-Stata入门-计量经济学及Stata应用及应用

? 陈强,2015年,《计量经济学及Stata应用》,高等教育出版社。 第2章 Stata入门 2.1 为什么使用Stata Stata软件因操作简单且功能强大,为目前在欧美最流行的统计与计量软件,拥有众多用户。 Stata公司定期升级软件,以适应计量经济学的迅猛发展。 Stata软件还留有“用户接口”,允许用户自己编写命令与函数,并上传到网上实现共享。一些最新计量方法,可在线查找和下载由用户编写的Stata命令程序(user-written Stata commands)。这些“非官方命令”(也称“外部命令”)的使用方法与官方命令完全相同,使得Stata的功能如虎添翼。 1

本教材使用Stata 13版本(2013年6月发布)。 对于绝大多数命令与功能,即使用更低的Stata版本(如Stata 11或Stata 12),也几乎没有差别。 2.2 Stata的窗口 安装Stata 13后,在安装的文件夹中将出现如下Stata 13图标(Stata 11或Stata 12的图标大同小异),参见图2.1: 图2.1 Stata 13的图标 双击此Stata图标,即可打开Stata。 2

3 如想在电脑桌面创建开启Stata 软件的快捷方式,可右键点击Stata 13的图标,然后选择“发送到”→“桌面快捷方式”,参见图2.2。 图2.2 发送Stata 13到桌面快捷方式

打开Stata后可看到,在最上方有一排“下拉式菜单”(pull-down menu),参见图2.3: 图2.3 Stata的下拉式菜单 在Stata中运行单个命令主要有两种方式,其一为点击菜单,其二为在“命令窗口”输入命令。 通过菜单执行命令(menu-driven)可能要点击多重菜单,通常还要填写对话框(dialog),以明确命令参数,不如在命令窗口直接输入命令方便。 在菜单之下,为一系列图标,起着快捷键的作用,参见图2.4。 4

计量经济学stata操作指南

计量经济学stata操作(实验课) 第一章stata基本知识 1、stata窗口介绍 2、基本操作 (1)窗口锁定:Edit-preferences-general preferences-windowing-lock splitter (2)数据导入 (3)打开文件:use E:\example.dta,clear (4)日期数据导入: gen newvar=date(varname, “ymd”) format newvar %td 年度数据 gen newvar=monthly(varname, “ym”) format newvar %tm 月度数据 gen newvar=quarterly(varname, “yq”) format newvar %tq 季度数据 (5)变量标签 Label variable tc ` “total output” ’ (6)审视数据 describe list x1 x2 list x1 x2 in 1/5 list x1 x2 if q>=1000 drop if q>=1000 keep if q>=1000 (6)考察变量的统计特征 summarize x1 su x1 if q>=10000 su q,detail su tabulate x1 correlate x1 x2 x3 x4 x5 x6 (7)画图 histogram x1, width(1000) frequency kdensity x1 scatter x1 x2 twoway (scatter x1 x2) (lfit x1 x2) twoway (scatter x1 x2) (qfit x1 x2) (8)生成新变量 gen lnx1=log(x1) gen q2=q^2 gen lnx1lnx2=lnx1*lnx2 gen larg=(x1>=10000) rename larg large

计量经济学基础与STATA应用

计量经济学基础与STATA应用 基本概念 【经典假设】 1、模型为线性;(多项式、对数、倒数、对数倒数、含有时间趋势) 2、X为变量; 3、残差序列(条件)均值为0; 4、残差序列(条件)方差齐性,即同方差; 5、残差序列之间无自相关性; 6、残差序列与解释变量不相关; 7、解释变量之间不存在完全的线性关系; 8、残差序列服从正态分布。 【残差正态性检验】 1、残差直方图:histogram e, norm freq 2、利用偏度系数和峰度系数:sktest 3、正态概率图: 问题检验与解决 【多重共线性】 完全多重共线性:参数无法唯一确定,方差无穷大。 不完全多重共线性:方差增大 诊断方法: 1、模型判定系数R方值高而具有显着的t值得变量少 2、解释变量之间有高度的两两相关 3、检查偏相关 4、辅助回归 5、病态指数 6、方差膨胀因子(VIF) 补救方法: 1、利用先验信息 2、横截面数据与时间序列数据并用 3、剔除变量(有可能出现模型的设定偏误) 4、变量替换(一阶差分:可能使得残差存在一定的相关性、比率:可能使得残差不再同方差) 5、补充新的数据 6、在多项式回归中降低共线性 【异方差】 原因: 1、按照边错边改边学习模型,人们在学习的过程中,其行为误差随着时间的延长而减少; 2、数据采集技术的改进

3、异常值出现 4、回归模型的设定不正确,如遗漏重要变量 5、回归元的分布呈偏态,如收入 6、不正确的数据变换或函数变换 7、横截面数据中更为常见 问题: 系数依旧无偏,估计方差增大,t值变小,从而导致本来显着地回归系数变成了统计不显着 诊断方法: 1、图解法:残差平方对y预测值或某一解释变量 2、帕克检验:先用OLS产生残差,再用残差平方对X回归,系数显着就有异方差; 3、格莱泽检验:先用OLS产生残差,用残差的绝对值对X的各种变换回归; 4、戈德菲尔德-匡特检验:先将X的观测值按升序排列,略去居中的c个观测,将前后分成两组分别 回归得到各自的残差平方和,做F检验 5、布劳殊-培干-戈弗雷检验(BPG检验):先回归得到残差平方和,计算残差平方和的均值,构造pi=ui2/ 均值,用pi对全部或部分X做回归,得到ESS,做卡方检验:estat hettest 6、怀特检验(White检验):回归得到残差平方和,用残差平方和对X和X方和X交叉项做回归,得 到R方,对nR2做卡方检验:estat imtest,white 7、寇因克-巴塞特检验(KB检验):残差平方和对预测Y平方做回归 解决: 当方差已知,WLS 当方差未知,误差方差正比于X2,两边除以X 误差方差正比于X,两边除以根号X 误差方差正比于Y均值的平方,两边除以Y均值 进行对数转换。 注意:一个好的模型,绝不会因为异方差性的原因而被抛弃。只有在问题严重的时候,误差方差不相等的问题才值得去修正。当模型参数的最大方差(OLS估计)比最小方差(GLS估计)的10倍还大时,问题才是严重的。 【自相关】 Cov(ui, uj) !=0 来源: 1、惯性:如GDP、价格指数 2、设定偏误,应含而未含变量,不正确的函数形式 3、蛛网现象:如供给价格的反应要滞后一个时期,今年种植的作物受去年流行的价格影响 4、滞后效应: 5、数据的编造 问题: OLS估计量仍是无偏线性的,方差估计错误 诊断方法: 1、图解法:残差对时间,残差对残差滞后 2、游程检验:runtest 3、德宾-沃森检验(DW检验):0-dl(拒绝正自相关),dl-du(无决定域),du-2-(4-du)(不拒绝)、(4-du)-(4-dl) (无决定域)、(4-dl)-4(拒绝负自相关):dwstat 4、布劳殊-戈弗雷检验:BG检验(LM检验) 解决: 如果AR(1),

计量经济学stata上机命令整理

计量经济学上机命令整理 实验一 edit 打开数据编辑器 browse 打开数据浏览器 rename 对变量重新命名 label save describe 对数据集简要描述 sort 排序例如:list in -10/-1 list 显示变量的数值 Generate 缩小:gen 生成新的变量后面可以接if条件句 Replace 替换append 覆盖 Summarize 缩写:su 总结后面可以接if条件句 实验二 twoway (scatter y x)(connected ey_x x) 在该散点图上,做出条件均值点 sc y x||lfit y x 画出线图和散点图 Reg y x 做出回归 Rename ** y **指原变量名用于修改变量名字 graph twoway scatter y x 画出y x 的二维散点图 Line y x 做出y x 的线条图 egen Ey_x=mean(y),by(x) 求在同一x水平下,求y的均值 实验三 Regress y x1 x2 ........做多元回归 Precict e,re 预测方差 Sort e 按照方差排序 Cor y x 测试y与x的相关程度 Pwcorr y x 也是测试y与x的相关程度 Set obs 90 (90为任意一个数字),增加一个或者多个样本值 Replace x=980 in 90 为第90个样本值赋值(980为任意一个数字) Predict yhat 预测y的估计值 Display invttail(n,p) n为自由度;p为概率(一般为0.025)。用来求t分布的t 值 Display ttail(n,t)知道t值求T

计量经济学基础与STATA应用

计量经济学基础与 S T A T A应用 LG GROUP system office room 【LGA16H-LGYY-LGUA8Q8-LGA162】

计量经济学基础与STATA应用 基本概念 【经典假设】 1、模型为线性;(多项式、对数、倒数、对数倒数、含有时间趋势) 2、X为变量; 3、残差序列(条件)均值为0; 4、残差序列(条件)方差齐性,即同方差; 5、残差序列之间无自相关性; 6、残差序列与解释变量不相关; 7、解释变量之间不存在完全的线性关系; 8、残差序列服从正态分布。 【残差正态性检验】 1、残差直方图:histogram e, norm freq 2、利用偏度系数和峰度系数:sktest 3、正态概率图: 问题检验与解决 【多重共线性】 完全多重共线性:参数无法唯一确定,方差无穷大。 不完全多重共线性:方差增大 诊断方法: 1、模型判定系数R方值高而具有显着的t值得变量少 2、解释变量之间有高度的两两相关 3、检查偏相关 4、辅助回归 5、病态指数 6、方差膨胀因子(VIF) 补救方法: 1、利用先验信息 2、横截面数据与时间序列数据并用 3、剔除变量(有可能出现模型的设定偏误) 4、变量替换(一阶差分:可能使得残差存在一定的相关性、比率:可能使得残差不再同方差) 5、补充新的数据 6、在多项式回归中降低共线性 【异方差】 原因: 1、按照边错边改边学习模型,人们在学习的过程中,其行为误差随着时间的延长而减少; 2、数据采集技术的改进

3、异常值出现 4、回归模型的设定不正确,如遗漏重要变量 5、回归元的分布呈偏态,如收入 6、不正确的数据变换或函数变换 7、横截面数据中更为常见 问题: 系数依旧无偏,估计方差增大,t值变小,从而导致本来显着地回归系数变成了统计不显着 诊断方法: 1、图解法:残差平方对y预测值或某一解释变量 2、帕克检验:先用OLS产生残差,再用残差平方对X回归,系数显着就有异方差; 3、格莱泽检验:先用OLS产生残差,用残差的绝对值对X的各种变换回归; 4、戈德菲尔德-匡特检验:先将X的观测值按升序排列,略去居中的c个观测,将前后分成两组分 别回归得到各自的残差平方和,做F检验 5、布劳殊-培干-戈弗雷检验(BPG检验):先回归得到残差平方和,计算残差平方和的均值,构造 pi=ui2/均值,用pi对全部或部分X做回归,得到ESS,做卡方检验:estat hettest 6、怀特检验(White检验):回归得到残差平方和,用残差平方和对X和X方和X交叉项做回归, 得到R方,对nR2做卡方检验:estat imtest,white 7、寇因克-巴塞特检验(KB检验):残差平方和对预测Y平方做回归 解决: 当方差已知,WLS 当方差未知,误差方差正比于X2,两边除以X 误差方差正比于X,两边除以根号X 误差方差正比于Y均值的平方,两边除以Y均值 进行对数转换。 注意:一个好的模型,绝不会因为异方差性的原因而被抛弃。只有在问题严重的时候,误差方差不相等的问题才值得去修正。当模型参数的最大方差(OLS估计)比最小方差(GLS估计)的10倍还大时,问题才是严重的。 【自相关】 Cov(ui, uj) !=0 来源: 1、惯性:如GDP、价格指数 2、设定偏误,应含而未含变量,不正确的函数形式 3、蛛网现象:如供给价格的反应要滞后一个时期,今年种植的作物受去年流行的价格影响 4、滞后效应: 5、数据的编造 问题: OLS估计量仍是无偏线性的,方差估计错误 诊断方法: 1、图解法:残差对时间,残差对残差滞后 2、游程检验:runtest 3、德宾-沃森检验(DW检验):0-dl(拒绝正自相关),dl-du(无决定域),du-2-(4-du)(不拒 绝)、(4-du)-(4-dl)(无决定域)、(4-dl)-4(拒绝负自相关):dwstat 4、布劳殊-戈弗雷检验:BG检验(LM检验) 解决:

伍德里奇---计量经济学第7章部分计算机习题详解(STATA)

班级:金融学×××班姓名:××学号:××××××× C7.10 NBASAL.RAW points=β0+β1exper+β2exper2+β3guard+β4forward+u 解:(ⅰ)估计一个线性回归模型,将单场得分与联赛中打球经历和位置(后卫、前锋或中锋)联系起来。包括打球经历的二次项形式,并将中锋作为基组。以通常形式报告结果。 由上图可知:points=4.76+1.28exper?0.072exper2+2.31guard+1.54forward 1.180.330.024 1.00 (1.00) n=269,R2=0.0910,R2=0.0772。 (ⅱ)在第(ⅰ)部分中,你为什么不将所有三个位置虚拟变量包括进来? 由于forward+center+guard=1,意味着forward和guard之和是center的一个线性函数,所以如果在模型中同时使用三个虚拟变量将会导致完全多重共线性,即包括三个位置虚拟变量会掉入虚拟变量陷阱,故不能将三个位置虚拟变量都包括在模型中。 (ⅲ)保持经历不变,一个后卫的得分比一个中锋多吗?多多少?这个差异统计显著吗? 由(ⅰ)中估计方程可知:一个后卫的得分比一个中锋多,且多得2.31分。同时,guard的t统计量为2.31,所以这个差异统计显著。 (ⅳ)现在,将婚姻状况加入方程。保持位置和经历不变,已婚球员是否更高效?

将婚姻状况加入方程后,回归结果如下所示: points=4.703+1.233exper?0.0704exper2+2.286guard+1.541forward+0.584marr 1.180.330.024 1.00 1.00 (0.74) n=269,R2=0.0931,R2=0.0759。 从方程中marr的系数不难发现:在保持位置和经历不变时,已婚球员每场得分比没结婚的球员高0.5分,可是事实上,变量marr的t统计量为0.789,t检验的p值为43.1%,所以marr统计并不显著,故无法得出“已婚球员得分更高效”的结论。 (ⅴ)加入婚姻状况和两个经历变量的交互项。在这个扩展的模型中,是否存在有力的证据表明婚姻状况影响单场得分? 由截图可知,变量marr、marrexper和marrexpersq联合不显著,无法拒绝原假设,所以并不存在有力的证据表明婚姻状况能够影响单场得分。 (ⅵ)使用单场助攻次数作为因变量估计(ⅳ)中的模型。与(ⅳ)的结果有明显的差异吗?请讨论。 当使用单场助攻次数作为因变量时,重新估计(ⅳ)中的模型,回归结果如下: assists=?0.226+0.444exper?0.0274exper2+2.492guard+0.447forward+0.322marr 0.3550.1000.0070.3010.301 (0.222) n=269,R2=0.3499,R2=0.3375。

斯托克,沃森计量经济学第四章实证练习stata操作及答案

E4.1 E4.2 E4.3 E4.4

VARIABLES ahe age 0.605 (0.0245) Constant 1.082 (0.688) Observations 7,711 R-squared 0.029 Robust standard errors in parentheses *** p<0.01, ** p<0.05, * p<0.1 1.①截距估计值estimated intercept:1.082 ②斜率估计值estimated slope:0.605 回归方程:ahe= 1.082+0.605*age ③当工人年长1岁,平均每小时工资增加0.605美元。 2.Bob: 0.605*26+1.082=16.812(美元) Alexis: 0.605*30+1.082=19.232(美元) 答:预测Bob的收入为每小时16.812美元,Alexis为19.232美元。 3.年龄不能解释不同个体收入变化的大部分。因为R-squared反映了因变量的 全部变化能通过回归关系被自变量充分解释的比例,而分析得R-squared的值为0.029,解释度低,说明年龄不能解释不同个体收入变化的大部分。

1. 答:两者看上去有微弱的正相关关系 2. VARIABLES course_eval beauty 0.133 (0.0550) Constant 3.998 (0.0449) Observations 463 R-squared 0.036 Robust standard errors in parentheses *** p<0.01, ** p<0.05, * p<0.1 ①截距估计值:3.998 斜率估计值:0.133 回归方程:Course_Eval=3.998+0.133*beauty

相关文档
相关文档 最新文档