Operands: IMsCompositeFormulaTermList;
The Operands property returns a collection of terms used to compose the equation.
Sub Main;
Var
MB: IMetabase;
CrInf: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Model: IMsModel;
ModelTrans: IMsFormulaTransform;
ECM: IMsErrorCorrectionModelTransform;
MissData: IMissingData;
Endo1, Endo2, Endo3, Endo4, Ekzo1: IMsVariableStub;
TransVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Eqution: IMsECMEquation;
Ar: Array[0..2] Of Integer;
ComposTerm: IMsCompositeFormulaTerm;
Begin
MB := MetabaseClass.Active;
//create a model
CrInf := Mb.CreateCreateInfo;
CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
CrInf.Id := "New_ECM";
CrInf.Name := "New_ECM";
CrInf.Parent := Mb.ItemById("KONT_MODEL");
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
ModelTrans := Model.Transform;
ModelTrans.Kind := MsModelKind.ErrorCorrectionModel;
//setting model parameters
ECM := Model.Transform.EquationsFormula.Method As IMsErrorCorrectionModelTransform;
ECM.ModelType := ECMType.NoTrendIntercept;
ECM.CointegralCount := 2;
MissData := ECM.MissingData;
MissData.Method := MissingDataMethod.NPointsAverage;
MissData.MethodParameter := 10;
// adding of endogenous variables to the list of outputs
Endo1 := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Outputs.Add(Endo1);
Endo2 := MB.ItemByIdNamespace("Var_2", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Outputs.Add(Endo2);
Endo3 := MB.ItemByIdNamespace("Var_3", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Outputs.Add(Endo3);
Endo4 := MB.ItemByIdNamespace("Var_4", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Outputs.Add(Endo4);
// adding of endogenous variable to the list of the inputs
Ekzo1 := MB.ItemByIdNamespace("Var_11", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Inputs.Add(Ekzo1);
// configuration of the first endogenous variable
TransVar := ModelTrans.Outputs.Item(0);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := ModelTrans.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
Formula.Level := DimCalendarLevel.Year;
Eqution := Formula.Method As IMsECMEquation;
Eqution.Inversion := MsInversion.Normalization;
Ar := New Integer[3];
Ar[0] := 1;
Ar[1] := 2;
Ar[2] := 3;
Eqution.AutoRegressionOrder := Ar;
Eqution.HasConstant := True;
// configuration of the endogenous variable for the first equation
TransVar := Model.Transform.Inputs.Item(0);
ComposTerm := Eqution.Operands.Add;
Slice := TransVar.Slices.Add(Null);
ComposTerm.Expression.AsString := "10*" + ModelTrans.SliceToTerm(Slice, "") + "*3.14";
// configuration of the second endogenous variable
TransVar := Model.Transform.Outputs.Item(1);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := ModelTrans.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
Eqution := Formula.Method As IMsECMEquation;
Eqution.Included := False;
// configuration of the third endogenous variable
TransVar := Model.Transform.Outputs.Item(2);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := ModelTrans.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
// configuration of the fourth endogenous variable
TransVar := Model.Transform.Outputs.Item(3);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := ModelTrans.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
MObj.Save;
End Sub Main;
After executing the example, the error correction model is created in the modeling container. For this model, the key parameters (type of model and number of cointegration connections) are determined, 4 variables are added into the list of endogenous variables. For the first equation one exogenous variable is added, and the order of autoregression is changed. The second equation is ignored in calculations.
See also: