Page 1 of 1

draw from truncated normal

Posted: Tue Oct 13, 2015 9:28 am
by PTillmann-436
Dear all,

I want to draw a latent variable from a truncated normal. Here I repeat the crucial commands. First, I specifiy two policy actions, easing and tightening:

set easing= loose ==1.0
set tighhtening= tight ==-1.0

set ystar = %if(tightening,-1.0,%if(easing,1.0,0.0))

The latent variable should be above 1 for easing, below -1 for tightening and between 1 and -1 otherwise:

compute ystar(time)=%if(easing(time),%rantruncate(cmean,cstddev,1.0,%na),$
%if(tightening(time),%rantruncate(cmean,cstddev,%na,-1.0),$
%rantruncate(cmean,cstddev,-1.0,1.0)))

The problem is that the estimated ystar is never below -1 despite several tightening observations. Where is the flaw?

Thanks a lot for your help.

Re: draw from truncated normal

Posted: Tue Oct 13, 2015 11:06 am
by TomDoan
You clearly left out a bunch of code that might be important. The following seems to work fine:

Code: Select all

set loose 1 500 = %ranflip(.1)
set tight 1 500 = %if(.not.loose,-%ranflip(.1),0.0)
set easing = loose==1.0
set tightening = tight ==-1.0
*
compute cmean=0.0,cstddev=2.0
*
clear ystar
*
do time=1,500
   compute ystar(time)=%if(easing(time),%rantruncate(cmean,cstddev,1.0,%na),$
     %if(tightening(time),%rantruncate(cmean,cstddev,%na,-1.0),$
      %rantruncate(cmean,cstddev,-1.0,1.0)))
end do time
Is it possible that you don't have the loop over TIME set up properly?

Re: draw from truncated normal

Posted: Tue Oct 13, 2015 12:52 pm
by PTillmann-436
Dear Tom,

Thanks for your prompt response. I am trying to generalize the codes for Dueker's Qual VAR from binary data to three alternative realizations.

Thanks again!

Re: draw from truncated normal

Posted: Tue Oct 13, 2015 1:53 pm
by TomDoan
Are you sure you have data points where tightening is non-zero and easing is zero, that is, have you checked whether the part of the program that's setting up your dummies is correct?

Re: draw from truncated normal

Posted: Tue Oct 13, 2015 2:07 pm
by PTillmann-436
I think it is now working (see graph). The tightening/easing periods are observed and plotted as shaded areas. The VAR-part seems to add little information as the latent variable mostly reflects the +1/-1 dummies, but at least the code seems to work.