楼主: sulight
3356 4

[stata资源分享] Monte Carlo Simulations using Stata进行蒙特卡罗运算 [推广有奖]

  • 0关注
  • 43粉丝

已卖:4948份资源

院士

44%

还不是VIP/贵宾

-

威望
0
论坛币
118973 个
通用积分
1634.9944
学术水平
363 点
热心指数
437 点
信用等级
344 点
经验
277402 点
帖子
4122
精华
0
在线时间
2226 小时
注册时间
2010-1-16
最后登录
2025-11-11

楼主
sulight 学生认证  发表于 2018-2-9 10:41:06 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
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

二维码

扫码加我 拉你入群

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

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

关键词:Simulations Monte Carlo Simulation ulation 蒙特卡罗运算 蒙特卡洛 stata 模拟

已有 4 人评分经验 论坛币 学术水平 热心指数 收起 理由
我的素质低 + 100 精彩帖子
葫芦娃大王 + 1 + 1 精彩帖子
zhanghui0931 + 60 + 40 + 1 + 3 精彩帖子
statax + 20 + 5 + 1 精彩帖子

总评分: 经验 + 181  论坛币 + 46  学术水平 + 2  热心指数 + 3   查看全部评分

沙发
pengming 在职认证  发表于 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 */


已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 鼓励积极发帖讨论

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

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

板凳
pengming 在职认证  发表于 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 */


已有 2 人评分经验 论坛币 学术水平 热心指数 收起 理由
葫芦娃大王 + 5 + 5 + 5 精彩帖子
zhanghui0931 + 60 + 40 + 2 + 3 精彩帖子

总评分: 经验 + 65  论坛币 + 45  学术水平 + 7  热心指数 + 3   查看全部评分

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

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-9 14:20