EquationsFormula: IMsFormula;
The EquationsFormula property returns equations formula.
Used for working with the error correction model and the system of non-linear equations.
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;
ECM: IMsErrorCorrectionModelTransform;
Endo1, Endo2, Endo3,Ekzo1: IMsVariable;
TransVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Eqution: IMsECMEquation;
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");
CrInf.Permanent := False;
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
Model.Kind := MsModelKind.ErrorCorrectionModel;
//determine model parameters
ECM := Model.Transform.EquationsFormula.Method As IMsErrorCorrectionModelTransform;
ECM.ModelType := ECMType.NoTrendIntercept;
ECM.CointegralCount :=2;
// add endogenous variables to list of output variables
Endo1 := MB.ItemByIdNamespace("Var_1",MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Endo1);
Endo2 := MB.ItemByIdNamespace("Var_2",MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Endo2);
Endo3 := MB.ItemByIdNamespace("Var_3",MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Endo3);
// add an exogenous variable to list of input variables
Ekzo1 := MB.ItemByIdNamespace("Var_11",MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Input.Add(Ekzo1);
// set up the first endogenous variable
TransVar := Model.Transform.Outputs.Item(0);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := Endo1.Transform.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;
// 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*" + Model.Transform.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 := Endo1.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
// set up the third endogenous variable
TransVar := Model.Transform.Outputs.Item(2);
Tree := TransVar.SlicesTree(Null);
Slice := Tree.CreateSlice(1);
Selector := Endo1.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.ECMEquation;
MObj.Save;
End Sub UserProc;
After executing the example an error correction model is created in the modeling container. For this model, the key parameters (model type and number of cointegration connections) are determined, 3 variables are added to the list of endogenous variables. One endogenous variable is added for the first equation.
See also: