Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stéphane Adjemian
dynare
Commits
a69f68bb
Verified
Commit
a69f68bb
authored
Jul 17, 2021
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Modify companion matrix if VAR model has a constant.
parent
1d5d46e1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
matlab/get_companion_matrix.m
+12
-5
12 additions, 5 deletions
matlab/get_companion_matrix.m
preprocessor
+1
-1
1 addition, 1 deletion
preprocessor
tests/var-expectations/11/example1.mod
+19
-5
19 additions, 5 deletions
tests/var-expectations/11/example1.mod
with
32 additions
and
11 deletions
matlab/get_companion_matrix.m
+
12
−
5
View file @
a69f68bb
...
...
@@ -42,7 +42,8 @@ if nargin < 2
end
if
strcmp
(
auxiliary_model_type
,
'var'
)
[
AR
,
~
]
=
feval
(
sprintf
(
'%s.varmatrices'
,
M_
.
fname
),
auxiliary_model_name
,
M_
.
params
,
M_
.
var
.
(
auxiliary_model_name
)
.
structural
);
[
AR
,
~
,
Constant
]
=
feval
(
sprintf
(
'%s.varmatrices'
,
M_
.
fname
),
auxiliary_model_name
,
M_
.
params
,
M_
.
var
.
(
auxiliary_model_name
)
.
structural
);
isconstant
=
any
(
abs
(
Constant
)
>
0
);
elseif
strcmp
(
auxiliary_model_type
,
'trend_component'
)
[
AR
,
A0
,
A0star
]
=
feval
(
sprintf
(
'%s.trend_component_ar_a0'
,
M_
.
fname
),
auxiliary_model_name
,
M_
.
params
);
else
...
...
@@ -57,11 +58,17 @@ n = length(M_.(auxiliary_model_type).(auxiliary_model_name).lhs);
switch
auxiliary_model_type
case
'var'
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
=
zeros
(
n
*
p
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
1
:
n
,
1
:
n
)
=
AR
(:,:,
1
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
=
zeros
(
n
*
p
+
isconstant
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
isconstant
+
(
1
:
n
),
isconstant
+
(
1
:
n
)
)
=
AR
(:,:,
1
);
for
i
=
2
:
p
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
1
:
n
,(
i
-
1
)
*
n
+
(
1
:
n
))
=
AR
(:,:,
i
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
((
i
-
1
)
*
n
+
(
1
:
n
),(
i
-
2
)
*
n
+
(
1
:
n
))
=
eye
(
n
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
isconstant
+
(
1
:
n
),
isconstant
+
(
i
-
1
)
*
n
+
(
1
:
n
))
=
AR
(:,:,
i
);
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
isconstant
+
(
i
-
1
)
*
n
+
(
1
:
n
),
isconstant
+
(
i
-
2
)
*
n
+
(
1
:
n
))
=
eye
(
n
);
end
if
isconstant
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
1
,
1
)
=
1
;
for
i
=
1
:
n
oo_
.
var
.
(
auxiliary_model_name
)
.
CompanionMatrix
(
1
+
i
,
1
)
=
Constant
(
i
);
end
end
M_
.
var
.
(
auxiliary_model_name
)
.
list_of_variables_in_companion_var
=
M_
.
endo_names
(
M_
.
var
.
(
auxiliary_model_name
)
.
lhs
);
if
nargout
...
...
This diff is collapsed.
Click to expand it.
preprocessor
@
e1f7d8c7
Compare
15d74321
...
e1f7d8c7
Subproject commit
15d7432105578c749cd5a81b2ab09fe8bf01d1b7
Subproject commit
e1f7d8c73556398a774ab55c8dc578c79ebb6c3b
This diff is collapsed.
Click to expand it.
tests/var-expectations/11/example1.mod
+
19
−
5
View file @
a69f68bb
...
...
@@ -21,16 +21,17 @@ var_expectation_model(model_name = varexp, expression = diff(log(x)), auxiliary_
model;
[ name = 'X' ]
diff(log(x)) = b*diff(z) + a*diff(log(x(-1))) + (1-a)*diff(log(x(-2))) + c*diff(z(-2)) + e_x;
diff(log(x)) = b*diff(z) + a*diff(log(x(-1))) +
b*
(1-a)*diff(log(x(-2))) + c*diff(z(-2)) + e_x;
[ name = 'Z' ]
diff(z) = f*(diff(z(-1))-diff(log(x)))+c*diff(z(-2)) + e_z;
diff(z) =
.1 +
f*(diff(z(-1))-diff(log(x)))+c*diff(z(-2)) + e_z;
[ name = 'Y' ]
log(y) = diff(log(x)) + d*log(y(-2)) + e*diff(z(-1)) + e_y;
foo = var_expectation(varexp);
end;
[ar, a0] = example1.varmatrices('toto', M_.params);
% Evaluate strutural VAR matrices
[ar, a0, const] = example1.varmatrices('toto', M_.params);
assert(isequal(diag(a0), ones(3,1)), 'Diagonal of a0 is wrong.')
...
...
@@ -41,6 +42,19 @@ assert(a0(2,3)==0, 'Element (2,3) in A0 is wrong.')
assert(a0(3,1)==f, 'Element (3,1) in A0 is wrong.')
assert(a0(3,2)==0, 'Element (3,1) in A0 is wrong.')
assert(isequal(ar(:,:,1), [a 0 0; 0 0 e; 0 0 f]), 'First autoregressive matrix is wrong')
;
assert(isequal(ar(:,:,2), [1-a 0 c; 0 d 0; 0 0 c]), 'Second autoregressive matrix is wrong')
;
assert(isequal(ar(:,:,1), [a 0 0; 0 0 e; 0 0 f]), 'First autoregressive matrix is wrong')
assert(isequal(ar(:,:,2), [
(
1-a
)*b
0 c; 0 d 0; 0 0 c]), 'Second autoregressive matrix is wrong')
assert(isequal(const, [.0;.0;.1]), 'Constant vector is wrong.')
% Evaluate reduced form VAR matrices
[AR, ~, CONST] = example1.varmatrices('toto', M_.params, true);
assert(all(all(abs(AR(:,:,1)-a0\ar(:,:,1))<1e-9)), 'Reduced form is wrong (first lag)')
assert(all(all(abs(AR(:,:,2)-a0\ar(:,:,2))<1e-9)), 'Reduced form is wrong (second lag)')
assert(all(abs(CONST-a0\const)<1e-9), 'Reduced form is wrong (constant)')
% Test get_companion_matrix when the VAR model has a constant.
get_companion_matrix('toto', 'var');
assert(all(all(abs(oo_.var.toto.CompanionMatrix-[1, zeros(1, 6); CONST, AR(:,:,1), AR(:,:,2); zeros(3,1), eye(3), zeros(3)])<1e-9)), 'Companion matrix is wrong')
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment