Operands: IMsCompositeFormulaTermList;
The Operands property returns a collection of terms used to compose the equation.
Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier.
Add links to the Metabase and Ms system assemblies.
Sub UserProc;
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;
//determine 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;
// add endogenous variables to list of output variables
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);
// add an exogenous variable to list of input variables
Ekzo1 := MB.ItemByIdNamespace("Var_11",MB.ItemById("KONT_MODEL").Key).Bind As IMsVariableStub;
ModelTrans.Inputs.Add(Ekzo1);
// set up 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;
// set up exogenous 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";
// set up 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;
// set up 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;
// set up 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 UserProc;
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. One exogenous variable is added for the first equation, and the autoregression order is changed. The second equation is ignored in calculation.
See also: