# Revision history [back]

Below is the output produced when running it.

Welcome to SHAZAM (Double Precision) v11.0 - JUNE 201 WIN-NT PAR=112400
...NOTE..CURRENT WORKING DIRECTORY IS:
C:\Users\DAVID~1.SOF\AppData\Local\Temp\SHAZDemo

* Example Monte-Carlo Simulations
*
* This example uses simulation to perform Interval Estimation
*
* 10 samples of data are generated by assuming that the true model
* coefficients are Beta1=45.0 and Beta2=0.14.
*
* The file NRAN.shd contains 40,000 random numbers generated from
* a N(0,1) distribution. Therefore, the number of replications
* of the experiment NREP can be set to 1000.
*
* This example demonstrates:
* Monte Carlo Simulation
* Descriptive Statistics
* SHAZAM Programming - DO Loops
*
* Reference: Section 5.1.3, pp.96-97 of
* R. Carter Hill, William E. Griffiths and George G. Judge,
* Undergraduate Econometrics, Second Edition, Wiley.
*
sample 1 40

read (tab3-1.shd) food income / skiplines=1

...NOTE..UNIT 88 IS NOW ASSIGNED TO: tab3-1.shd
...NOTE.. 2 VARIABLES AND 40 OBSERVATIONS STARTING AT OBS 1

* Set the "true" model coefficients
gen1 beta1=45.0
gen1 beta2=0.14
gen1 sigsq=1400

* Set the number of random samples
gen1 nrep=10
set nodoecho nooutput
dim b2 nrep se2 nrep var nrep

* Use a DO-loop to do repeat operations
do #=1,nrep

* Read some random numbers from a N(0,1) distribution
read (nran.shd) e / byvar norewind

* Change the variance
genr e=e*sqrt(sigsq)

* Generate Y
genr y = beta1 + beta2 * income + e

* Run an OLS regression and save the estimated coefficients.
ols y income / coef=btemp stderr=setemp
gen1 var:#=\$sig2
gen1 b2:#=btemp:1
gen1 se2:#=setemp:1

endo

* Turn output on again
set output

* Print the results
sample 1 nrep
genr n=time(0)

* Table 5.1, p.97
format(1x,f12.0,f12.4,f12.4,f14.4)
print n b2 se2 var / format

N  B2  SE2  VAR
1.  0.1442  0.0378  2193.4597
2.  0.1442  0.0378  2193.4597
3.  0.1442  0.0378  2193.4597
4.  0.1442  0.0378  2193.4597
5.  0.1442  0.0378  2193.4597
6.  0.1442  0.0378  2193.4597
7.  0.1442  0.0378  2193.4597
8.  0.1442  0.0378  2193.4597
9.  0.1442  0.0378  2193.4597
10.  0.1442  0.0378  2193.4597

stat b2

Name N Mean St. Dev Variance Minimum Maximum
B2 10 0.14416 0.29257E-16 0.85597E-33 0.14416 0.14416

* Interval estimation
* Get a critical value from the t-distribution
sample 1 1
gen1 alpha=0.025
distrib alpha / type=t df=38 inverse critical=tc

T DISTRIBUTION DF=   38.000
VARIANCE=   1.0556       H=   1.0000

PROBABILITY CRITICAL VALUE   PDF
ALPHA
ROW     1    0.25000E-01  2.0244     0.53786E-01

* Construct the interval estimates
sample 1 nrep
genr b2low=b2-tc*se2
genr b2up=b2+tc*se2

* Table 5.2, p.97
print n b2low b2up / format

N  B2LOW  B2UP
1.  0.0676  0.2207
2.  0.0676  0.2207
3.  0.0676  0.2207
4.  0.0676  0.2207
5.  0.0676  0.2207
6.  0.0676  0.2207
7.  0.0676  0.2207
8.  0.0676  0.2207
9.  0.0676  0.2207
10.  0.0676  0.2207