## Restrict variance and estimate it - two country model

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

### Restrict variance and estimate it - two country model

Hi all,

I am working on a two-country model where the exogenous process is characterised by a VAR with two variables, for example the TFP of each country. That is:

Z(t) = A*Z(t-1) + E
where Z is a 2x1 vector (i.e the Solow residual of each country), A is a 2x2 matrix and E is a 2x1 vecotr of shocks with some variance-covariance matrix.

As it is often in two-country models, I would like to impose symmetry across countries, that means same persistence, spillovers and variance of the two shocks (I don't mind about the covariance). In terms of restrictions, that would be:

- the diagonal elements of A are equal to each other.
- the off-diagonal elements of A are equal to each other.
- the variance of the shocks is the same, which means that the diagonal elements of the variance-covariance matrix are the same.

I have been suggested to do that in Dynare using a standad Maximum Likelihood estimation without setting a prior. In the manual, I see that if one would like to have the variance of a variable estimated could do

estimated_params ;
stderr VARIABLE_NAME
...

My question is, how I could ask Dynare to estimate the variance of my shocks, i.e. e(1) and e(2), under the restriction that they have the same variance?
I hope this is clear enough, but I am happy to provde more clarifications. Thanks a lot!

Kyriacos
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

Use a trick. Set the variances in the shock block to 1 and do not estimate them. Instead, put a scaling coefficient for the standard deviation in front of the shocks and estimate them instead. For example, if you have two shocks that should have the same variance:
Code: Select all
`model;a=rho*a(-1)+std_shock*eps1;a=rho*a(-1)+std_shock*eps2;end;shocks;stderr eps1=1;stderr eps2=1;end;estimated_params;std_shock ...end;`

where std_shock is now the common standard deviation.
------------
Johannes Pfeifer
University of Cologne
jpfeifer

Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

### Re: Restrict variance and estimate it - two country model

Hi,

Thanks a lot for your reply. I have tried it, but I keep getting an error message and I do not know why.

??? Error using ==> print_info at 36
MJDGGES returns the following error code: 18

Error in ==> check at 50
print_info(info, options_.noprint);

Error in ==> BS_CapitalServices3IST at 1015
check;

Error in ==> dynare at 132
evalin('base',fname) ;

The model_diagnostics gives me the following:

model_diagnostics(M_,options_,oo_)
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.

Error in ==> rank at 15
s = svd(A);

Error in ==> model_diagnostics at 131
rank_jacob = rank(jacob);

When I type M_.params there are three NaN entries. I am pretty sure that these correspond to the three parametres I want to estimate. I do not really see where I am wrong, I am uploading the var_obs from an Excel file and the col-headers have the same names as the var_obs. Can you give me some hints? Sorry, I am quite new in estimation.

Note that the model calibrated works fine. Also, I know that you might ask to see the .mod file but believe me, it is pretty huge. Plus, I solve the steady-state externally using fsolve...

Kyriacos
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

You correctly defined all parameters except for the ones you estimate by calibration. Thus, estimation should run. But you don't get to estimation, because you use check before estimation, which does not take into account the estimated_params-block. This leads to a crash as rhoI1, rhoI12, stdr_ist were not set before. Either you calibrate rhoI1, rhoI12, stdr_ist before check (which is then later overwritten by estimated_params) or you take out the check.
------------
Johannes Pfeifer
University of Cologne
jpfeifer

Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

### Re: Restrict variance and estimate it - two country model

Thanks!
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

Hi again,

can you suggest a similar trick for estimating the covariance between the shocks? Thanks

K.

jpfeifer wrote:Use a trick. Set the variances in the shock block to 1 and do not estimate them. Instead, put a scaling coefficient for the standard deviation in front of the shocks and estimate them instead. For example, if you have two shocks that should have the same variance:
Code: Select all
`model;a=rho*a(-1)+std_shock*eps1;a=rho*a(-1)+std_shock*eps2;end;shocks;stderr eps1=1;stderr eps2=1;end;estimated_params;std_shock ...end;`

where std_shock is now the common standard deviation.
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

Basically, when I include the covariance into the estimation I get weird messages, I am not even sure if Dynare takes into account the covariance when doing the MLE estimation. Here is the message I get. Note also that t-stats cannot be computed. Thanks again!

K.

Improvement on iteration 10 = 0.000000062
improvement < crit termination
warning: possible inaccuracy in H matrix
Objective function at mode: -172.044543
Objective function at mode: -172.044543

POSTERIOR KERNEL OPTIMIZATION PROBLEM!
(minus) the hessian matrix at the "mode" is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong!
> In dynare_estimation_1 at 643
In dynare_estimation at 62
In BS_CapitalServices3IST1 at 1061
In dynare at 132
Warning: Matrix is singular to working precision.
> In dynare_estimation_1 at 652
In dynare_estimation at 62
In BS_CapitalServices3IST1 at 1061
In dynare at 132

RESULTS FROM MAXIMUM LIKELIHOOD
parameters
Estimate s.d. t-stat

stdr_ist 0.0157 Inf 0.0000
rhoI1 0.9676 Inf 0.0000
rhoI12 0.0298 Inf 0.0000
corrv 0.0010 Inf 0.0000
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

Covariances are a tricky issue. We have had some trouble implementing them and don't know on the top of my head where we are currently standing. Usually it is easiest to introduce an additional common shock. Note that the error message above mostly says that you have not found a valid maximum of the likelihood function.
------------
Johannes Pfeifer
University of Cologne
jpfeifer

Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

### Re: Restrict variance and estimate it - two country model

Hi again,

I am coming back to the estimation of the covariance. I tried to use your advice in assuming a common shock. In particular, I set my exogenous processes as follows:

v1 = rhoI1*v1(-1) + rhoI12*v2(-1) + stdr_ist*(eta1 + PHI*eta3) ;
v2 = rhoI1*v2(-1) + rhoI12*v1(-1) + stdr_ist*(eta2 + PHI*eta3);

Thus, the variance of the "overall" shock is stdr_ist^2 + (stdr_ist^2)*(PHI^2) and the covariance is stdr_ist*PHI (correct??). Then, my shock block writes:

shocks ;
var eta1 = 1;
var eta2 = 1;
var eta3 = 1;
end;

and I do not set anything for the covariance. If I estimate only rhoI1, rhoI12 and stdr_ist (MLE without setting a prior), it converges normally and I get rather logical results:

Improvement on iteration 11 = 0.000000000
improvement < crit termination
Objective function at mode: -169.780830
Objective function at mode: -169.780830

RESULTS FROM MAXIMUM LIKELIHOOD
parameters
Estimate s.d. t-stat

stdr_ist 0.0161 0.0014 11.2415
rhoI1 0.9651 0.0022 438.0741
rhoI12 0.0326 0.0031 10.4305
Note 1: Theta is 2
Note 2: Epsilon is 2
Note 3: Interim period is 0
Total computing time : 0h00m09s

However, I am not sure what Dynare assumes as the covariance between the shocks. Does it indeed assume/impose zero covariance?? Trying to estimate PHI becomes a mess, as it is extremely sensitive to the initial condition. If I set the latter to 0.02, say:

estimated_params ;
stdr_ist , 0.0126 ,,;
rhoI1 , 0.95 , ,;
rhoI12 , 0.0202 , , ;
PHI , 0.02, , ;
end;

estimation(datafile=istshocks1, mode_compute=4) ; %mode_compute=4

it converges and gives me what seem to be logical results.

Improvement on iteration 303 = 0.000000090
improvement < crit termination
Objective function at mode: -171.298880
Objective function at mode: -171.298880

RESULTS FROM MAXIMUM LIKELIHOOD
parameters
Estimate s.d. t-stat

stdr_ist 0.0147 0.0043 3.4273
rhoI1 0.9558 0.0022 441.7531
rhoI12 0.0417 0.0034 12.1793
PHI 0.3894 0.7154 0.5443
Note 1: Theta is 2
Note 2: Epsilon is 2
Note 3: Interim period is 0
Total computing time : 0h00m44s

Nevertheless, even the most minor changes to this initial condition cause trouble. Initial conditions of PHI = 0.019 and 0.0199 (!!) result to the message of no convergence:

POSTERIOR KERNEL OPTIMIZATION PROBLEM!
(minus) the hessian matrix at the "mode" is not positive definite!
=> posterior variance of the estimated parameters are not positive.
You should try to change the initial values of the parameters using
the estimated_params_init block, or use another optimization routine.
Warning: The results below are most likely wrong!
> In dynare_estimation_1 at 643
In dynare_estimation at 62
In BS_CapitalServices3IST1 at 1066
In dynare at 132

Setting PHI = 0.019999 does converge but the estimated parametres are a bit different from the case where the initial condition is 0.02.

My questions are:
1. When I do not set anything for the covariance and I do not ask for the estimation of PHI, does Dynare indeed assume /impose a zero covariance? That is, are the persistence coefficient and the common standard deviation estimated with ML under the restriction of zero covariance?

2. The issues of non-convergence and extreme sensitivity to initial conditions are not normal right? What can it mean? Would you suggest another way to estimate the covariance as well?

Thanks a lot again!!

Kyriacos
kyri82

Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

### Re: Restrict variance and estimate it - two country model

1. By default, the covariance matrix is diagonal and contains the variances of the shocks-block, unless you estimate the variances/covariances or set them via calibration of the model. Only then Dynare fills changes the entries and fills the specified off-diagonal elements.

2. The issues of non-convergence and extreme sensitivity to initial conditions are not completely normal. You might want to check identifiability via the identification command. A good way often is also simulating the model with specified parameters and then estimating it again on the simulated data. My own experience is that estimating AR-processes with only few data (both series and points) often does not work that well. Things become particularly complicated, if embedded in big models. Derivative-based optimizers often get stuck at local minima. If nothing else works, run mode_compute=9 (which might take a lot of time, but looks for a global minimum).

As a sidenote: The variance of the "overall" shock is really stdr_ist^2 + (stdr_ist^2)*(PHI^2), but your covariance is wrong. It is (stdr_ist*PHI)^2. I attach two mod-files estimating the covariance. The first one, correl_shocks_estim.mod, generates the data from your specification above, saves the simulated data, and then does ML estimation. In the parameters, I also compute the true correlation and variance of the shock processes for comparison in the second mod-file.

The second mod-file, correl_shocks_estim_dynare_corr_command.mod, features the second way of proceeding. It uses the corr-statement in estimation. I only use two shocks eta1 and eta2 that are correlated and estimate the variances and the correlation on the data generated from the other mod-file. As you can see, the estimation delivers the same results (i.e. correlation and standard deviation) as in the other file. Thus, both ways of estimation are valid and equivalent.

You can play around with the starting values, but both results seem pretty robust. But note that both AR-processes are assumed to be fully observed. The fact that you run into trouble suggests a more general problem with the mapping of observables to the parameters, given that you surely have unobserved states.

I hope this helps.
Attachments
correl_shocks_estim_dynare_corr_command.mod
Uses the Dynare routine to estimate the correlation
correl_shocks_estim.mod
Simulates the AR-process, saves the data and then estimates it.
------------
Johannes Pfeifer
University of Cologne
jpfeifer

Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

### Re: Restrict variance and estimate it - two country model

Hi,

I have a very similar question:

In the paper "What's news in business cycles", the authors restrict the variance of the shocks as follows:

var(e0)/(var(eo) + var(e4) + var(8)) = 0.75

where var(e0) is the unanticipated shock and var(e4) and var(e8) are anticipated shocks.

How could i tell dynare to estimate the variance of these shocks with this restriction?
Cfarias

Posts: 11
Joined: Sat Nov 12, 2016 6:21 pm

### Re: Restrict variance and estimate it - two country model

In the SGU "What's news in business cycles"-paper they do not impose this restriction during estimation. It only applies to the prior specification.
------------
Johannes Pfeifer
University of Cologne