ExternalEquations: IMsModelList;
The ExternalEquations property returns the collection of external models in the system.
Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier. This container must include models with the MODEL and MODEL_EX identifiers, and variables with the X1, Y1, X2, and Y2 identifiers.
Add links to the Metabase, Ms, Cubes, Stat system assemblies.
Sub UserProc;
Var
Model, Model_ex: IMsModel;
Desc: IMetabaseObjectDescriptor;
obj: IMetabaseObject;
ModelSpace: IMetabaseObjectDescriptor;
mb: IMetabase;
Equations: IMsLinearEquationsTransform;
ExternalEquations: IMsModelList;
Method: IMsMethod;
X1, X2, Y1, Y2, XY2, XY1: IMsFormulaTransformVariable;
Outputs, Inputs: IMsFormulaTransformVariables;
Selector: IMsFormulaTransformSelector;
Formula, f1, f2: IMsFormula;
lr: IMsLinearRegressionTransform;
CompositeTerm: IMsCompositeFormulaTerm;
info: IMsFormulaTermInfo;
Trans: IMsFormulaTransform;
vY1, vY2, vX1, vX2: IMsVariable;
Begin
mb := MetabaseClass.Active;
ModelSpace := mb.ItemById("CONT_MODEL");
Desc := mb.ItemByIdNamespace("MODEL", ModelSpace.Key);
obj := Desc.Edit;
Model := obj As IMsModel;
Trans := Model.Transform;
Outputs := Trans.Outputs;
Outputs.Clear;
Inputs := Trans.Inputs;
Inputs.Clear;
Trans.Kind := MsModelKind.LinearEquations;
Method := Model.Transform.EquationsFormula.Method;
Equations := Method As IMsLinearEquationsTransform;
ExternalEquations := Equations.ExternalEquations;
If ExternalEquations.Count > 0 Then
ExternalEquations.Clear;
End If;
Model_ex := mb.ItemByIdNamespace("MODEL_EX", ModelSpace.Key).Bind As IMsModel;
ExternalEquations.Add(Model_ex);
Equations.MissingData.Method := MissingDataMethod.LinTrend;
// Endogenous variables
vY1 := mb.ItemByIdNamespace("Y1", ModelSpace.Key).Bind As IMsVariable;
vY2 := mb.ItemByIdNamespace("Y2", ModelSpace.Key).Bind As IMsVariable;
vX1 := mb.ItemByIdNamespace("X1", ModelSpace.Key).Bind As IMsVariable;
vX2 := mb.ItemByIdNamespace("X2", ModelSpace.Key).Bind As IMsVariable;
Y1 := Outputs.Add(vY1 As IVariableStub);
Y2 := Outputs.Add(vY2 As IVariableStub);
X1 := Inputs.Add(vX1 As IVariableStub);
X2 := Inputs.Add(vX2 As IVariableStub);
XY2 := Inputs.Add(vY2 As IVariableStub);
XY1 := Inputs.Add(vY1 As IVariableStub);
// First equation in system
Selector := Model.Transform.CreateSelector;
Selector.Slice := Y1.Slices.Add(Null);
Trans := Model.Transform;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.LinearRegression;
lr := Formula.Method As IMsLinearRegressionTransform;
lr.MissingData.Method := MissingDataMethod.PrevValue;
lr.HasConstant := True;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := X1.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := XY2.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
f1 := Formula;
Equations.EstimateSimultaneously(f1) := True;
If Equations.IdentifiableState(f1) = MsEquationIdentifiableState.NonIdentifiable Then
Debug.WriteLine(First equation is not identified);
End If;
// Second equation in system
Selector := Model.Transform.CreateSelector;
Selector.Slice := Y2.Slices.Add(Null);
Trans := Model.Transform;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.LinearRegression;
lr := Formula.Method As IMsLinearRegressionTransform;
lr.HasConstant := False;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := X2.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := XY1.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
f2 := Formula;
Equations.EstimateSimultaneously(f2) := True;
If Equations.IdentifiableState(f2) = MsEquationIdentifiableState.NonIdentifiable Then
Debug.WriteLine("the second equation is unidentified");
End If;
obj.Save;
End Sub UserProc;
After executing the example the system of simultaneous equations, containing two equations of linear regression and one external model, is created.Data about identifiability of the equations is displayed in the console window.
See also: