From 973c3955f010a6af831be589a27342c9af7e4cb7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 25 Sep 2018 14:58:36 +0200 Subject: [PATCH] =?UTF-8?q?adjust=20for=20=E2=80=98targets=E2=80=99=20keyw?= =?UTF-8?q?ord=20instead=20of=20=E2=80=98trends=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matlab/get_companion_matrix.m | 30 ++++++++++++++-------------- matlab/get_companion_matrix_legacy.m | 30 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/matlab/get_companion_matrix.m b/matlab/get_companion_matrix.m index 9edd14eda..70d333c71 100644 --- a/matlab/get_companion_matrix.m +++ b/matlab/get_companion_matrix.m @@ -70,17 +70,17 @@ switch auxiliary_model_type end case 'trend_component' % Get number of trends. - q = sum(M_.trend_component.(auxiliary_model_name).trends); + q = sum(M_.trend_component.(auxiliary_model_name).targets); % Get the number of equations with error correction. m = n - q; % Get the indices of trend and EC equations in the auxiliary model. - trend_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).trends); - ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends); + target_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).targets); + ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).targets); % Get the indices of trend equations in model. - trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn; + target_eqnums = M_.trend_component.(auxiliary_model_name).target_eqn; % REMARK It is assumed that the non trend equations are the error correction % equations. We assume that the model can be cast in the following form: @@ -124,36 +124,36 @@ switch auxiliary_model_type % Check that there is only one variable on the rhs and update trend_autoregressive_variables. v = M_.trend_component.(auxiliary_model_name).rhs.vars_at_eq{id_trend_in_var(i)}.var; if length(v) ~= 1 - error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end % Check that the variables on lhs and rhs have the same difference orders. if get_difference_order(trend_variables(i)) ~= get_difference_order(v) - error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end % Check that the trend equation is autoregressive. if isdiff(v) if ~M_.aux_vars(get_aux_variable_id(v)).type == 9 - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) else if M_.aux_vars(get_aux_variable_id(v)).orig_index ~= trend_variables(i) - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end end else if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index ~= trend_variables(i) - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end end end - % Reorder trend_eqnums_in_auxiliary_model to ensure that the order of + % Reorder target_eqnums_in_auxiliary_model to ensure that the order of % the trend variables matches the order of the error correction % variables. - [~,reorder] = ismember(M_.trend_component.(auxiliary_model_name).lhs(trend_eqnums_in_auxiliary_model), ... - M_.trend_component.(auxiliary_model_name).trend_vars(M_.trend_component.(auxiliary_model_name).trend_vars > 0)); - trend_eqnums_in_auxiliary_model = trend_eqnums_in_auxiliary_model(reorder); + [~,reorder] = ismember(M_.trend_component.(auxiliary_model_name).lhs(target_eqnums_in_auxiliary_model), ... + M_.trend_component.(auxiliary_model_name).target_vars(M_.trend_component.(auxiliary_model_name).target_vars > 0)); + target_eqnums_in_auxiliary_model = target_eqnums_in_auxiliary_model(reorder); % Get the EC matrix (the EC term is assumend to be in t-1). % @@ -162,8 +162,8 @@ switch auxiliary_model_type % % Build B matrices (VAR in levels) B(ecm_eqnums_in_auxiliary_model, ecm_eqnums_in_auxiliary_model, 1) = eye(m) + A0 + AR(:,:,1); - B(ecm_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = -A0; - B(trend_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = eye(q); + B(ecm_eqnums_in_auxiliary_model, target_eqnums_in_auxiliary_model) = -A0; + B(target_eqnums_in_auxiliary_model, target_eqnums_in_auxiliary_model) = eye(q); for i = 2:p B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i) - AR(:,:,i-1); end diff --git a/matlab/get_companion_matrix_legacy.m b/matlab/get_companion_matrix_legacy.m index e8f67b00b..e9ce5aa33 100644 --- a/matlab/get_companion_matrix_legacy.m +++ b/matlab/get_companion_matrix_legacy.m @@ -67,14 +67,14 @@ switch auxiliary_model_type M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs); case 'trend_component' % Get number of trends. - q = sum(M_.trend_component.(auxiliary_model_name).trends); + q = sum(M_.trend_component.(auxiliary_model_name).targets); % Get the number of equations with error correction. m = n-q; % Get the indices of trend and EC equations in the auxiliary model. - trend_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).trends); - ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends); + target_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).targets); + ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).targets); % Get the indices of trend equations in model. - trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn; + target_eqnums = M_.trend_component.(auxiliary_model_name).target_eqn; % REMARK It is assumed that the non trend equations are the error correction % equations. We assume that the model can be cast in the following form: % @@ -115,34 +115,34 @@ switch auxiliary_model_type % Check that there is only one variable on the rhs and update trend_autoregressive_variables. v = M_.trend_component.(auxiliary_model_name).rhs.vars_at_eq{id_trend_in_var(i)}.var; if length(v)~=1 - error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end trend_autoregressive_variables(i) = v; % Check that the variables on lhs and rhs have the same difference orders. if get_difference_order(trend_variables(i))~=get_difference_order(trend_autoregressive_variables(i)) - error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end % Check that the trend equation is autoregressive. if isdiff(v) if ~M_.aux_vars(get_aux_variable_id(v)).type==9 - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) else if M_.aux_vars(get_aux_variable_id(v)).orig_index~=trend_variables(i) - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end end else if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index~=trend_variables(i) - error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) + error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{target_eqnums(i)}) end end end - % Reorder trend_eqnums_in_auxiliary_model to ensure that the order of + % Reorder target_eqnums_in_auxiliary_model to ensure that the order of % the trend variables matches the order of the error correction % variables. - [~,reorder] = ismember(M_.trend_component.(auxiliary_model_name).lhs(trend_eqnums_in_auxiliary_model), ... - M_.trend_component.(auxiliary_model_name).trend_vars(find(M_.trend_component.(auxiliary_model_name).trend_vars>0))); - trend_eqnums_in_auxiliary_model = trend_eqnums_in_auxiliary_model(reorder); + [~,reorder] = ismember(M_.trend_component.(auxiliary_model_name).lhs(target_eqnums_in_auxiliary_model), ... + M_.trend_component.(auxiliary_model_name).target_vars(find(M_.trend_component.(auxiliary_model_name).target_vars>0))); + target_eqnums_in_auxiliary_model = target_eqnums_in_auxiliary_model(reorder); % Get the EC matrix (the EC term is assumend to be in t-1). % % TODO: Check that the EC term is the difference between the @@ -153,8 +153,8 @@ switch auxiliary_model_type AR = oo_.trend_component.(auxiliary_model_name).ar(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,:); % Build B matrices (VAR in levels) B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,1) = eye(m)+A0+AR(:,:,1); - B(ecm_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = -A0; - B(trend_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = eye(q); + B(ecm_eqnums_in_auxiliary_model,target_eqnums_in_auxiliary_model) = -A0; + B(target_eqnums_in_auxiliary_model,target_eqnums_in_auxiliary_model) = eye(q); for i=2:p B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i)-AR(:,:,i-1); end