Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: simulate

From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: simulate
Date   Wed, 25 Aug 2004 21:07:37 -0400

Frank said

I am learning STATA programming. The following
question seems very basic, but I wasted much time
debugging it and failed to get through.

I copied the following codes exactly from somewhere,
but I can not get it running in STATA 8.1. What's the

Here is a working version. Note that you need _b[_cons], and the program must be rclass:

capt program drop _all
set seed 10101
program define simrandm, rclass
version 8.2
if "`1'"=="?" {
global S_1 "b_const se_const b_slope se_usual se_white"
drop _all
set obs 20
gen x = invnorm(uniform())
gen u = x*invnorm(uniform())
gen y = 1+1*x + u
regress y x, robust
scalar sewhite=_se[x]
regress y x
return scalar a= _b[_cons]
return scalar as= _se[_cons]
return scalar b= _b[x]
return scalar sb= _se[x]
return scalar sw= sewhite
simulate "simrandm" a=r(a) as=r(as) b=r(b) bs=r(sb) bw=r(sw), reps(1000)


* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index