Contributor
Posts: 39

Record the coefficient in OLS regression_in each simulation

Lets say we have a regression model y= b0+b1*X

I'm trying to write a code which in each cycle of simulated data (lets say for example _10,000 cycles)

doing an OLS regression and just record the b1 coefficient.

the output should be about 10,000 b1 _the number the of cycles.

The creation of b1 data will give me the opportunity to calculate statistic on that parameter.

I would really appreciate your help.

Thank you all,

Orit

Posts: 3,852

Re: Record the coefficient in OLS regression_in each simulation

1. make a data set with 10000 samples of the data
1. use SURVEYSELECT if it is random sample of existing data REP=10000
2. if the data is generated by programming generate 10000 levels of a BY variable REP.
2. run PROC REG OUTEST=
3. BY REP;
SAS Super FREQ
Posts: 4,243

Re: Record the coefficient in OLS regression_in each simulation

This and many other examples and variations are discussed in my book Simulating Data with SAS

data RegSim;
call streaminit(1);
do SampleID = 1 to 10000;   /* number of simulated samples */
do i = 1 to 50;                     /* number of obs per sample */
x = rand("Uniform");
eps = rand("Normal", 0, 0.5);
y = 1 - 2*x + eps;     /* parameters are 1 and -2 */
output;
end;
end;
run;

proc reg data=RegSim NOPRINT outest=OutEst;
by SampleID;
model y = x;
run;

proc means data=OutEst;
var x;
run;

In this example, I generate new x values for each sample. You can also generate a single set of x values and reuse it for all samples, so that only the error term is random between samples (discussion on p. 202).

Contributor
Posts: 39

Re: Record the coefficient in OLS regression_in each simulation

Thank you!

Orit

Discussion stats
• 3 replies
• 191 views
• 0 likes
• 3 in conversation