## Basic Simulation

Occasional Contributor
Posts: 7

# Basic Simulation

My name is Kuda Makoni from the University of Malawi and i wanted to ask a basic stata question

This is a pretty basic question but i am trying to do a simulation.

I have the following equation

y=3.4+0.58b_1 +0.89b_2

so i am trying to see how much y would change if I increased b_1 to 0.9 while b_2 stayed the same.

How do i write a simulation code for that?

Kuda
Super User
Posts: 23,667

## Re: Basic Simulation

Determine the range of values for b_1/2.
Simulate those values and then run both models to compare.
Occasional Contributor
Posts: 7

## Re: Basic Simulation

How do i do that basically what i am trying to do is

simulation but i am not sure how to do the code. I have a linear equation

y=c+0.05X1+1.28X2

so here i am trying to obtain the values of y and b2 when I fix b1 first at 2 then 0

How do i do that?

Posts: 5,521

## Re: Basic Simulation

So you have a function

y(b_1, b_2) = 3.4 + 0.58b_1 + 0.89b_2,

define a new function as

dy(b_1, b_2) = y(b_1, b_2 + 0.9) - y(b_1, b_2)

choose a range for b_1 and b_2, and a resolution db for your simulation

Calculate the values of dy

``````data simul;
low_b_1 = 0;
high_b_1 = 3;
low_b_2 = -2;
high_b_2 = 2;
db = 0.1;
do b_1 = low_b_1 to high_b_1 by db;
do b_2 = low_b_2 to high_b_2 by 1;
dy = 3.4 + 0.58*b_1 + 0.89*(b_2+0.9) - (3.4 + 0.58*b_1 + 0.89*b_2);
output;
end;
end;
keep b_1 b_2 dy;
run;``````

Plot the results with proc sgplot or sgpanel.

``````proc sgplot data=simul;
series y=dy x=b_1 / group=b_2;
run;

proc sgpanel data=simul;
panelby b_2;
series y=dy x=b_1;
run;``````

Of course, the results will not look very interesting unless dy is not a constant function... but you get the idea.

PG
Occasional Contributor
Posts: 7

## Re: Basic Simulation

I am so confused right now i am just  trying to do a simulation but i am not sure how to do the code. I have a linear equation

y=c+0.05X1+1.28X2

so here i am trying to obtain the values of y and b2 when I fix b1 first at 2 then 0

How do i do that?

Super User
Posts: 10,766

## Re: Basic Simulation

It is totally depended on the coefficient of b_1 ( 0.58 ), since you don't care about other covariables.

y=3.4+0.58b_1 +0.89b_2

==>

y-3.4-0.89b_2=0.58b_1

So,

y1-3.4-0.89b_2=0.58(b_1+0.9)

-

y0-3.4-0.89b_2=0.58b_1

=> y1-y0=0.58*0.9

Occasional Contributor
Posts: 7

## Re: Basic Simulation

I am a bit confused the only thing i am trying to do is a simulation but i am not sure how to do the code. I have a linear equation

y=c+0.05X1+1.28X2

so here i am trying to obtain the values of y and b2 when I fix b1 first at 2 then 0

How do i do that?

Super User
Posts: 23,667