全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
3291 4
2018-02-09
Monte Carlo Simulations using Stata
Oklahoma State University州立大学的Lee C. Adkins教授的课件,
主要内容包括:
Introduction
Software Choices
two methods used for simulation in Stata.
some examples from the paper.
compare speed of simulate, postfile, and gretl.
Paper Examples

pdf文件里面有书签,

为减轻网站流量负担,请各位战友根据论坛币下载。
祝各位战友学习愉快!!!



附件里的code如下:
replace x = theta*L.x + rnormal() in 2
replace u = rho*L.u + rnormal(0,sigma) in 2

replace y = beta*x+delta*L.y + u in 2

reg y x /* b1 */
reg L(0/1).y x /* b2 */
prais L(0/1).y x /* b3 */
reg L(0/2).y L(0/1).x /* b4 */
program regIV, rclass
tempname sim
postfile `sim' gam r2 b biv using results, replace
quietly {
foreach gam of numlist 0.025 0.0375 0.05 0.1 0.15 {
forvalues i = 1/$nmc {
replace u = rnormal()
replace x = `gam'*z+rho*u+rnormal(0,sige)
replace y = slope*x + u
....
}

regIV
use results, clear
by gam, sort: summarize r2 F biv b
by gam, sort: summarize p_ls p_iv
by gam: egen Fbar = mean(F) /* Avg F by gamma */
by gam: egen tslsbar = mean(biv) /* Avg biv by gamma */
by gam: egen olsbar = mean(b) /* Avg b by gamma */
by gam: egen r2bar = mean(r2) /* Avg r2 by gamma */
gen tsls_bias = tslsbar-1 /* IV bias */
gen ols_bias = olsbar-1 /* OLS bias */
gen relb = tsls_bias/ols_bias /* relative bias */
gen rot = 1/(Fbar-1) /* rule of thumb */
gen t = _n /* observation numbers */
keep if mod(t,1000) == 0 /* keep 1 obs per design */
reg relb c.rot##c.rot, noconst /* rel. bias onto rot */
reg relb rot, noconst
test (rot=-1) /* directly proportional? */
}
}
postclose `sim'
end

# Set the sample size and save it in n
nulldata 100
scalar n = $nobs
set seed 3213799
# Set the values of the parameters
scalar slope = 10
scalar sigma = 20
scalar delta = .7
scalar rho = .9
# initialize variables
series u = normal()
series y = normal()
series x = uniform()

loop 400 --progressive --quiet
series e = normal(0,sigma)
series u=rho*u(-1)+e
series y = slope*x + delta*y(-1) + u
ols y const x y(-1)
ols y const x
ar 1; y const x y(-1)
ols y const x y(-1) x(-1) y(-2)
endloop

附件列表
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2018-2-9 16:38:38
附件第12页,最后两行命令需要更改为
summarize b
kdensity b, normal normopts(lwidth(medium) lpattern(dash))
对发文的朋友的网页的程序进行调整,可以执行。
clear
drop _all
set obs 1000
set seed 123456
gen year = _n
gen x = runiform(5,10)
gen y = runiform(10,20)
gen u = rnormal()
tsset year
replace x = 0.25*L.x + rnormal()  in 2/1000   //从第2行开始替代直到第1000行
replace u = 0.5*L.u + rnormal(0,5)  in 2/1000 //从第2行开始替代直到第1000行
replace y = 0.75*x+0.9*L.y + u  in 2/1000  //从第2行开始替代直到第1000行
reg y x                        /* b1 */
reg L(0/1).y x                /* b2 */
prais L(0/1).y x             /* b3 */
reg L(0/2).y L(0/1).x       /* b4 */


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-9 17:10:43
pengming 发表于 2018-2-9 16:38
附件第12页,最后两行命令需要更改为
summarize b
kdensity b, normal normopts(lwidth(medium) lpattern ...
谢谢您,这么仔细。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-9 18:04:18
sulight 发表于 2018-2-9 17:10
谢谢您,这么仔细。
网页上的代码是不能执行的,我按照代码原理,进行部分修改,可以执行。
clear
drop _all
set obs 1000
set seed 123456
gen year = _n
gen x = runiform(5,10)
gen y = runiform(10,20)
gen u = rnormal()
tsset year
replace x = 0.25*L.x + rnormal()  in 2/1000   //从第2行开始替代直到第1000行
replace u = 0.5*L.u + rnormal(0,5)  in 2/1000 //从第2行开始替代直到第1000行
replace y = 0.75*x+0.9*L.y + u  in 2/1000  //从第2行开始替代直到第1000行drop  in 1
reg y x                        /* b1 */
reg L(0/1).y x                /* b2 */
prais L(0/1).y x             /* b3 */
reg L(0/2).y L(0/1).x       /* b4 */


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-2-10 01:53:15
pengming 发表于 2018-2-9 18:04
网页上的代码是不能执行的,我按照代码原理,进行部分修改,可以执行。
clear
drop _all
中国好坛友!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群