Page 1 of 1
QUANTILE
Posted: Wed Jul 28, 2010 10:40 am
by comac
Dear all,
In the code below I am computing some different betas (say beta1 and beta2) from bootstrapped-VAR residuals. How can I obtain quantiles for beta1 and beta2?
Code: Select all
@VARBootSetup(model=varmodel) bootvar
*
compute rstart=%regstart()
compute rend =%regend()
*
compute bootdraws=2000
compute nvar =3
compute nsteps=8
*
dec vect[rect] beta1(bootdraws)
dec vect[rect] beta2(bootdraws)
*
infobox(action=define,progress,lower=1,upper=bootdraws) $
"Bootstrap Simulations"
do draw=1,bootdraws
@VARBootDraw(model=varmodel,resids=resids) rstart rend
*
* Estimate the model with resampled data
*
estimate(noprint,noftests)
....instructions.....
compute beta1 = [....instructions.....]
compute beta2 = [....instructions.....]
end do draw
infobox(action=remove)
Following the
User's Guide, Chpt. 13 I have inserted in the code and hence in the loop:
Code: Select all
dec vect[rect] sims(bootdraws)
….
compute sims(draw) = beta1(draw)
….
compute fract=%fractiles(sims,||.25,.75||)
the simulation works just fine, but then I get the following error message :
Can't Find Match for %FRACTILES(VECTOR(VECTOR),RECTANGULAR). Closest Match is %FRACTILES(MATRIX(REAL),VECTOR)
## SX27. Illegal Combination of Data Types for Operation
>>>>s(sims,||.25,.75||)<<<<
Does anybody know how to make them match?
Thank you,
C
Re: QUANTILE
Posted: Wed Jul 28, 2010 12:22 pm
by TomDoan
%FRACTILES applies to only one "vector" of data at a time so you have to extract each set of bootstrapped values in turn for each of the coefficients. Do something like this:
Code: Select all
dec rect[vect] fract(%rows(beta1),%cols(beta1))
dec vect onevect(bootdraws)
dec integer k
*
do i=1,%rows(beta1)
do j=1,%cols(beta1)
ewise onevect(k)=sims(k)(i,j)
compute fract(i,j)=%fractiles(onevect,||.25,.75||)
end do j
end do i
That will give you an N x K set of two vectors with the .25 and .75 percentiles for each coefficient.
Re: QUANTILE
Posted: Wed Jul 28, 2010 12:36 pm
by comac
Tom -- this is helpful. However i get the following error message:
## SX11. Identifier K is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>> ewise onevect(k)<<<<
How could I help it?
Thank you,
C.
Re: QUANTILE
Posted: Wed Jul 28, 2010 12:52 pm
by TomDoan
Just add
I've fixed the post above.
Re: QUANTILE
Posted: Wed Jul 28, 2010 1:05 pm
by comac
Tom -- sorry for bothering.
The code needs 'sims' to be declared itself. I added to your code. The program does not crash but in the output below there is obviously something wrong.
Code: Select all
dec rect[vect] fract(%rows(beta1),%cols(beta1))
dec vect onevect(bootdraws)
dec integer k
dec vect[rect] sims(bootdraws)
*
compute sims(draw) = betauip(draw)
do i=1,%rows(beta1)
do j=1,%cols(beta1)
ewise onevect(k)=sims(k)(i,j)
compute fract(i,j)=%fractiles(onevect,||.25,.75||)
end do j
end do i
-0.63567 -0.22892 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
To simplify things, I would be happy if I could get quantiles of the whole distribution (and not coefficient by coefficient). Is there some way? Are the two coefficients overthere those for the whole distribution of beta1?
Thank you again.
Re: QUANTILE
Posted: Wed Jul 28, 2010 1:41 pm
by TomDoan
Since
sims was supposed to be the source for the simulations, the fact that it isn't defined would be a major problem in computing the percentiles of the simulations. Your loop should actually read:
Code: Select all
compute beta1(draw) = [....instructions.....]
compute beta2(draw) = [....instructions.....]
I assumed because of the way you wrote it that
beta1 and
beta2 were representatives of what you wanted to save, rather than the actual storage of the bootstrap draws. (It's usually better to include the complete set of instructions rather than trying to paraphrase).
So where I said
sims, you actually want
beta1 (and beta2 in a separate loop) and where I said %rows(beta1) and %cols(beta1) you want the rows and columns of whatever you were saving.
Re: QUANTILE
Posted: Thu Jul 29, 2010 5:34 am
by comac
Tom -- thank you! Still, I am a bit confused.
I am saving beta1 as I want a distribution for that, and consequently fractiles for its distribtuion.
Following your hint I've substituted 'sims' with 'beta1' in the inside-loop.
Code: Select all
compute rstart=%regstart()
compute rend =%regend()
*
compute bootdraws=100
compute nvar =5
compute nsteps=8
dec vect[rect] beta1(bootdraws)
dec rect[vect] fract(%rows(beta1),%cols(beta1))
dec vect onevect(bootdraws)
dec integer k
*
infobox(action=define,progress,lower=1,upper=bootdraws) $
"Bootstrap Simulations"
do draw=1,bootdraws
@VARBootDraw(model=varmodel,resids=resids) rstart rend
*
* Estimate the model with resampled data
*
estimate(noprint,noftests) rstart rend
[...instructions.....] *
compute beta1(draw) = [....instructions.....]
do i=1,%rows(beta1)
do j=1,%cols(beta1)
ewise onevect(k)=beta1(k)(i,j)
compute fract(i,j)=%fractiles(onevect,||.025,.975||)
end do j
end do i
*
infobox(current=draw)
end do draw
infobox(action=remove)
dis fract
The results are just fine for fractile(1,1).
The problem is that (as before) the quantiles other than the one in (1,1) are not defined. As the code is writte, I guess those in (1,1) are quantiles for the whole
distribution of beta1.Isn't it?
-1.61601 1.41303 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Thank you for your patience,
C.
Re: QUANTILE
Posted: Thu Jul 29, 2010 6:41 am
by TomDoan
You have to move the calculation of the quantiles
outside the loop. So the loop should look like:
Code: Select all
infobox(action=define,progress,lower=1,upper=bootdraws) $
"Bootstrap Simulations"
do draw=1,bootdraws
@VARBootDraw(model=varmodel,resids=resids) rstart rend
*
* Estimate the model with resampled data
*
estimate(noprint,noftests) rstart rend
[...instructions.....] *
compute beta1(draw) = [....instructions.....]
*
infobox(current=draw)
end do draw
infobox(action=remove)
The dimensions of FRACT need to be the dimensions of what you're saving in beta1, not beta1 itself. (beta1 is the storage for the set of draws). I'm guessing that the columns are nvar and I'll call the rows # of regressors. So the post-loop processing is:
Code: Select all
dec rect[vect] fract(# of regressors,nvar)
dec vect onevect(bootdraws)
dec integer k
do i=1,# of regressors
do j=1,nvar
ewise onevect(k)=beta1(k)(i,j)
compute fract(i,j)=%fractiles(onevect,||.025,.975||)
end do j
end do i
dis fract
Re: QUANTILE
Posted: Thu Jul 29, 2010 10:04 am
by comac
I am sorry. Probably I was completely unclear about it.
Beta1 is computed as a scalar and beta1 in the loop collects them all.
Hence, I am setting fract(1,1), right?
If it is so, the code works just perfectly. Many thanks.
Code: Select all
dec rect[vect] fract(1,1)
dec vect onevect(bootdraws)
dec integer k
do i=1,1
do j=1,1
ewise onevect(k)=beta1(k)(i,j)
compute fract(i,j)=%fractiles(onevect,||.025,.975||)
end do j
end do i
dis fract
Re: QUANTILE
Posted: Thu Jul 29, 2010 11:37 am
by TomDoan
If you're collecting a scalar, then that would be correct.