Using PARMSETS to organize statistics
Posted: Mon Jan 13, 2014 11:15 am
We were sent a program which included the following (as part of the collection of statistics across bootstrap replications):
A cleaner and more flexible way to handle this is to use a PARMSET, even though these aren't directly being used in a non-linear estimation. However, the PARMSET allows you to organize a set of otherwise unrelated variable. (Note that while, in this case, these are all scalars, they could be a mix of scalars and matrices, just like any other PARMSET).
Before you start the bootstrapping loop, you do the following:
Then, inside the loop you replace the above 42 lines with
%PARMSPEEK(parmset) returns a VECTOR with whatever are the current contents of the parmset. So inside the bootstrap or simulation loop, you would just do whatever calculations are required to generate the new values of those parameters, exactly as would be done if they weren't in the parmset. The parmset just offers a way to organize them for the purpose of updating the statistics.
Note that, unlike the hard-coded calculations, you can easily change the set of statistics that you accumulate by just changing the NONLIN instruction.
Code: Select all
compute a1 = a1 + Psir
compute a2 = a2+Psiw
compute a3 = a3+dR
compute a4 = a4+dy
compute a5 = a5+dw
compute a6 = a6+hdelta
compute a7 = a7+hR
compute a8 = a8+hy
compute a9 = a9+hw
compute a10 = a10+fR
compute a11 = a11+fy
compute a12 = a12+fn
compute a13 = a13+fmp
compute a14 = a14+fmb
compute a15 = a15+theta
compute a16 = a16+Shockvarb1
compute a17 = a17+Shockvarb2
compute a18 = a18+Shockvarb3
compute a19 = a19+Shockvarb4
compute a20 = a20+Shockvarb5
compute a21 = a21+Shockvarb6
compute a1sqr = a1sqr+(Psir^2)
compute a2sqr = a2sqr+(Psiw^2)
compute a3sqr = a3sqr+(dR^2)
compute a4sqr = a4sqr+(dy^2)
compute a5sqr = a5sqr+(dw^2)
compute a6sqr = a6sqr+(hdelta^2)
compute a7sqr = a7sqr+(hR^2)
compute a8sqr = a8sqr+(hy^2)
compute a9sqr = a9sqr+(hw^2)
compute a10sqr = a10sqr+(fR^2)
compute a11sqr = a11sqr+(fy^2)
compute a12sqr = a12sqr+(fn^2)
compute a13sqr = a13sqr+(fmp^2)
compute a14sqr = a14sqr+(fmb^2)
compute a15sqr = a15sqr+(theta^2)
compute a16sqr = a16sqr+(Shockvarb1^2)
compute a17sqr = a17sqr+(Shockvarb2^2)
compute a18sqr = a18sqr+(Shockvarb3^2)
compute a19sqr = a19sqr+(Shockvarb4^2)
compute a20sqr = a20sqr+(Shockvarb5^2)
compute a21sqr = a21sqr+(Shockvarb6^2)
Before you start the bootstrapping loop, you do the following:
Code: Select all
nonlin(parmset=bootstats) psir pswi dr dy dw hdelta hr hy hw fr fy fn fmp fmb theta $
shockvarb1 shockvarb2 shockvarb3 shockvarb4 shockvarb5 shockvarb6
compute nstats=%size(%parmspeek(bootstats))
dec vect asum asumsq
compute asum=%zeros(nstats,1),asumsq=%zeros(nstats,1)
Code: Select all
compute asum=asum+%parmspeek(bootstats)
compute asumsq=asumsq+%parmspeek(bootstats).^2
Note that, unlike the hard-coded calculations, you can easily change the set of statistics that you accumulate by just changing the NONLIN instruction.