RATS 10.1
RATS 10.1

TVARYING.RPF is an example of time-varying parameters VAR. From the User's Guide, Sections 7.14.2,7.14.3.

Full Program

 

cal(q) 1959
open data haversample.rat
data(format=rats) 1959:1 2006:4 gdph fm1

log gdph
log fm1

compute kstart=1960:1,kend=2006:4

equation kalmeq gdph
# constant gdph{1 to 4} fm1{1 to 4}
declare vector b(9) bmean(9)
ewise bmean(i)=(i==2)
associate(perm) kalmeq b
*
linreg gdph
# constant gdph{1 to 4}
compute gseesq=.9*%seesq
linreg fm1
# constant fm1{1 to 4}
compute mseesq=.9*%seesq
*
*  Set up the system. Use GSEESQ as the measurement equation variance
*
system kalmeq
kfset(constant,noscale,likelihood=likely) xxx
# gseesq
tvarying tvx
end(system)
*
* The hyperparameters (PIx) below are the following:
*   PI5 = Overall tightness. This corresponds to TIGHTNESS**2 on
*         SPECIFY.
*   PI2 = Relative tightness on other variables. This corresponds
*         to w**2 on the symmetric prior.
*   PI3 = Relative tightness on the constant. (No correspondence).
*   PI7 = Relative tightness on time variation.
*   PI8 = Shrinkage factor toward mean (between 0 and 1 , 1 = no shrinkage)
*
*  This uses a HARMONIC decay with DECAY=.5
*
compute pi5 = .20**2
compute pi2 = .5**2
compute pi3 = 10000.
compute pi7 = 0.00000001
compute pi8 = 1.00
*
dim xxx(9,9) tvx(9,9)
*
compute likely=%const(0.0)
compute b=bmean
compute xxx=%const(0.0)
compute xxx(1,1)=pi5*pi3*gseesq
do i=1,4
  compute decayfac=i**(-2*.5)
  compute xxx(i+1,i+1)=pi5*decayfac
  compute xxx(i+5,i+5)=pi5*pi2*decayfac*gseesq/mseesq
end do i
compute tvx=pi7*xxx
*
do time=kstart,kend
  if time==kstart
     kalman(start=time)
  else {
     compute b=pi8*b+(1-pi8)*bmean
     compute xxx=(pi8**2)*xxx
     kalman(print=(time==kend))
     }
end do time
*
*  Compute the concentrated log likelihood
*
compute nobs=kend-kstart+1
compute loglikely=-.5*(likely(1,1)+nobs*log(likely(2,1)/nobs))

compute pi5 = .20**2 , pi2 = .5**2 , pi3 = 10000.
compute pi7 = 0.00000001 , pi8 = 1.00
nonlin pi8 pi7
dec real loglikely
dim xxx(9,9) tvx(9,9)
find(method=genetic,iterations=200) maximum loglikely {
   if pi7<0.or.pi8>1.00 {
      compute loglikely=%na
      next
   }
   compute likely=%const(0.0)
   compute b=bmean
   compute xxx=%const(0.0)
   compute xxx(1,1)=pi5*pi3*gseesq
   do i=1,4
     compute decayfac=i**(-2*.5)
     compute xxx(i+1,i+1)=pi5*decayfac
     compute xxx(i+5,i+5)=pi5*pi2*decayfac*gseesq/mseesq
   end do i
   compute tvx=pi7*xxx
*
   do time=kstart,kend
      if time==kstart
       kalman(start=time)
      else {
        compute b=pi8*b+(1-pi8)*bmean
        compute xxx=(pi8**2)*xxx
        kalman
    }
   end do time
   compute nobs=kend-kstart+1
   compute loglikely=-.5*(likely(1,1)+nobs*log(likely(2,1)/nobs))
}
end find
 

Output

 

Linear Regression - Estimation by Least Squares

Dependent Variable GDPH

Quarterly Data From 1960:01 To 2006:04

Usable Observations                       188

Degrees of Freedom                        183

Centered R^2                        0.9996540

R-Bar^2                             0.9996464

Uncentered R^2                      0.9999991

Mean of Dependent Variable       8.6324850619

Std Error of Dependent Variable  0.4316368147

Standard Error of Estimate       0.0081162154

Sum of Squared Residuals         0.0120547504

Regression F(4,183)               132178.6002

Significance Level of F             0.0000000

Log Likelihood                       640.7850

Durbin-Watson Statistic                1.9626

 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  Constant                      0.020392668  0.012056163      1.69147  0.09244878

2.  GDPH{1}                       1.217407118  0.073758692     16.50527  0.00000000

3.  GDPH{2}                      -0.058554015  0.115526790     -0.50684  0.61287472

4.  GDPH{3}                      -0.186799332  0.113578117     -1.64468  0.10175309

5.  GDPH{4}                       0.026197898  0.072293464      0.36238  0.71748424

 

Linear Regression - Estimation by Least Squares

Dependent Variable FM1

Quarterly Data From 1960:01 To 2006:04

Usable Observations                       188

Degrees of Freedom                        183

Centered R^2                        0.9998897

R-Bar^2                             0.9998873

Uncentered R^2                      0.9999983

Mean of Dependent Variable       6.1687053805

Std Error of Dependent Variable  0.7805932208

Standard Error of Estimate       0.0082873900

Sum of Squared Residuals         0.0125685923

Regression F(4,183)               414713.0563

Significance Level of F             0.0000000

Log Likelihood                       636.8612

Durbin-Watson Statistic                2.0063

 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  Constant                      0.008971455  0.004931246      1.81931  0.07049880

2.  FM1{1}                        1.532889693  0.072875519     21.03436  0.00000000

3.  FM1{2}                       -0.376453959  0.133875853     -2.81196  0.00546115

4.  FM1{3}                       -0.111167371  0.134237861     -0.82814  0.40867149

5.  FM1{4}                       -0.046206319  0.073345862     -0.62998  0.52949443

 

VAR/System - Estimation by Kalman Filter

Quarterly Data From 1960:01 To 2006:04

Usable Observations                       188

 

Dependent Variable GDPH

Mean of Dependent Variable       8.6324850619

Std Error of Dependent Variable  0.4316368147

Standard Error of Estimate       0.0080077164

Sum of Squared Residuals         0.0120552222

Durbin-Watson Statistic                1.8412

 

    Variable                        Coeff      Std Error      T-Stat      Signif

************************************************************************************

1.  Constant                      0.086552765  0.044251977      1.95591  0.05047607

2.  GDPH{1}                       1.161107016  0.059304239     19.57882  0.00000000

3.  GDPH{2}                      -0.039702753  0.080713454     -0.49190  0.62279175

4.  GDPH{3}                      -0.109263931  0.071434525     -1.52957  0.12612381

5.  GDPH{4}                      -0.026476913  0.050557162     -0.52370  0.60048547

6.  FM1{1}                        0.059896869  0.039870927      1.50227  0.13302758

7.  FM1{2}                       -0.021374042  0.053186735     -0.40187  0.68778124

8.  FM1{3}                       -0.048988569  0.043814137     -1.11810  0.26352445

9.  FM1{4}                        0.017437230  0.031481233      0.55389  0.57965218

 

FIND Optimization - Estimation by Genetic

Convergence in    34 Iterations. Final criterion was  0.0000063 <=  0.0000100

Function Value                       891.4792

 

    Variable                        Coeff

**********************************************

1.  PI8                               0.99503

2.  PI7                          1.79506e-008


 


Copyright © 2025 Thomas A. Doan