全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2223 5
2012-10-16
研究了很久stata都不是很会,老师给的作业做了一天也不懂

求教高手..其中一个题目感觉很简单就是不会做...

assume a model and a disturbance term u: Y= a+b*x+u
choose 30 obs of data for x, and values for the parameters of the model
c)generate a disturbance term using a normal disturibution with zero mean and unit varinace. then generate the value of Y
d)regress Y on x using the ols estimation technique and collect the estimated coefficient b1 and b2
repeat c) and d) 200 times and generate two scatter plot graphs, one for each b1 and b2.

需要先设置model吗?基本做到b问就卡住了,以前学都是winrats什么之类的,stata第一次接触,有没有比较好的教程....谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2012-10-16 05:10:31
enjoy!


clear

//here is ur data;
set obs 300
gen x=runiform()

//randomly select 10% of data
sample 10


gen a=2
gen b=3

//run 200 times
forval x=1/200 {
preserve

//generate a disturbance term using a normal disturibution with zero mean and 1 varinace
gen u=rnormal(0,1)

//create y based on a and b
gen  y=a+b*x+u

//save coefficents into matrix
qui regress y x
if `x'==1 {
matrix M=e(b)
}
else {
matrix M=M\e(b)
}

restore
}

//matrix into data
clear
svmat M, names(b)

//plot
scatter b1 b2
二维码

扫码加我 拉你入群

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

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

2012-10-16 08:02:40
大白菜2012 发表于 2012-10-16 05:10
enjoy!
非常感性大神
二维码

扫码加我 拉你入群

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

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

2012-10-16 08:17:00
哈哈,小朋友是在学习计量吧,你老师风格很像我认识的某位澳大利亚籍老师。

楼上给出的是stata,你还是用matlab做吧。
二维码

扫码加我 拉你入群

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

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

2012-10-16 08:53:55
大白菜2012 发表于 2012-10-16 05:10
enjoy!
大神,

if 'x' == 1{
matrix M=e(b)
}

else{
matrix M=M\e(b)
}


这好像不对,出不来,然后最后的clear需要吗?最后
svmat M, names(b)


scatter b1 b2

也出不来.....求解....谢谢
二维码

扫码加我 拉你入群

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

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

2012-10-16 09:09:57
fishkk123 发表于 2012-10-16 08:53
大神,

if 'x' == 1{
`x' instead of 'x'
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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