小编Dav*_*ong的帖子

使用 R 的 Montecarlo 模拟(如何为 R“翻译”Stata 代码)

我需要从 Stata 到 R 运行相同的练习(蒙特卡罗模拟)。

我在 Stata 中使用的代码是下面的代码。我如何使用 R 做到这一点?(我已经搜索了很多教程,但我仍然没有设法在 R 中做到这一点)。

* Simulations (10, 100 and 1000 sample replications/iterations)

clear
drop _all
set obs 100
set seed 54231
gen x = ((rnormal()))*10 + 40

* Generating true_y, considering Beta = 0,035
 
gen true_y = 5+0.03500*x
save truth, replace
twoway scatter true_y x

program hetero1
version 13
args c
use truth, clear
gen y = true_y + rnormal()
regress y x
end


foreach i in 10 100 1000 {
simulate …
Run Code Online (Sandbox Code Playgroud)

r montecarlo stata

-1
推荐指数
1
解决办法
70
查看次数

标签 统计

montecarlo ×1

r ×1

stata ×1