Hello,
please try this script.
nulldata 1000
set seed 16577899
scalar umf_sample = 1000
series a = 0
matrix tab_beta = a
loop for (t=1; t<= umf_sample; t++) --quiet
smpl 1 20
res = normal(0,1)
matrix m_Quadratmeter = {40,55,28,81,107,130,74.5,96,63,46,37.5,150,87,30,65,70,92,49,83,105}
series Quadratmeter = m_Quadratmeter
series Miete = 9.33 + 9.18*Quadratmeter + res
ols Miete const Quadratmeter --quiet
scalar beta = $coeff(Quadratmeter)
smpl 1 umf_sample
tab_beta[t:t,1] = beta
endloop
series a = tab_beta
printf "Schätzer beta = %.6f ", mean(a)
Try it with umf_sample (=Sample size) = 20, 100, 500 and you will see, that beta (the beta coefficient) will be nearer to the value 9.18.
I construct the variable Miete with residuals and values of m_Quadratmeter. The residuals (variable res) are constructed with the command normal(0,1). Therefore they have mean 0 and std-error 1.
Then I construct Miete with the formula: Miete = 9.33 + 9.18*Quadratmeter + res
All 20 (100, 500) beta-values are saved in a tab_beta with size 20 (100,500). At end the mean ist calculated. The higher
the sample_size, the more precise is the variable a (in aspect of the value 9.18 !!!). That is what you want !!!
I hope that I could help you.
With greetings
Jürgen Malitte
-----Original-Nachricht-----
Betreff: [Gretl-users] Monte Carlo Simulation
Datum: Tue, 16 Dec 2014 14:46:34 +0100
Von: "Alessandra .Cruanes Aguilar" <alessandra.cruanes@gmail.com>
An: gretl-users@lists.wfu.edu
nulldata 200
setobs --time-series
scalar n=$nobs
scalar beta1=0.8
scalar rho=0.4
smpl 1 1
series u=0
series y=0
smpl 2 200
series e=randgen(N,0,1)
series u=rho*u(-1)+e
series y=beta1*y(-1)+u
ols y y(-1) --simple
loop 5000 --progressive --quiet
series e=randgen(N,0,1)
series u=rho*u(-1)+e
series y=beta1*y(-1)+u
ols y y(-1)
scalar beta1hat= $coeff(y_1)
scalar s1= $stderr(y_1)
scalar bias=$coeff(y_1)-beta1
genr LB = beta1hat - critical(t,$df,0.025)*s1
genr UB = beta1hat + critical(t,$df,0.025)*s1
print beta1 beta1hat bias LB UB
endloop
smpl 50 --random --replace
loop 5000 --progressive --quiet
series e=randgen(N,0,1)
series u=rho*u(-1)+e
series y=beta1*y(-1)+u
ols y y(-1)
scalar beta1hat= $coeff(y_1)
scalar s1= $stderr(y_1)
scalar bias=$coeff(y_1)-beta1
genr LB = beta1hat - critical(t,$df,0.025)*s1
genr UB = beta1hat + critical(t,$df,0.025)*s1
print beta1 beta1hat bias LB UB
endloop