Chapter Contents Previous Next
 The MODEL Procedure

## Solving Simultaneous Nonlinear Equation Systems

You can use a SOLVE statement to solve the nonlinear equation system for some variables when the values of other variables are given.

Consider the demand and supply model shown in the preceding example. The following statement computes equilibrium price (EEGP) and quantity (EEC) values for given observed cost (CCIUTC) values and stores them in the output data set EQUILIB.

   title1 'Supply-Demand Model using General-form Equations';
proc model data=sashelp.citimon;
endogenous eegp eec;
exogenous exvus cciutc;
parameters a1 a2 a3 b1 b2 ;
label eegp   = 'Gasoline Retail Price'
eec    = 'Energy Consumption'
cciutc = 'Consumer Debt';

/* -------- Supply equation ------------- */
eq.supply = eec - (a1 + a2 * eegp + a3 * cciutc);

/* -------- Demand equation ------------- */
eq.demand = eec - (b1 + b2 * eegp );

/* -------- Instrumental variables -------*/
lageegp = lag(eegp); lag2eegp=lag2(eegp);

/* -------- Estimate parameters --------- */
instruments _EXOG_ lageegp lag2eegp;
fit supply demand / n3sls ;
solve eegp eec / out=equilib;
run;


As a second example, suppose you want to compute points of intersection between the square root function and hyperbolas of the form a+b/x. That is, solve the system:

(hyperbola)y = a+[b/x]

The following statements read parameters for several hyperbolas in the input data set TEST and solve the nonlinear equations. The SOLVEPRINT option on the SOLVE statement prints the solution values. The ID statement is used to include the values of A and B in the output of the SOLVEPRINT option.

   data test;
input a b @@;
datalines;
0 1   1 1   1 2
;

proc model data=test;
eq.sqrt      = sqrt(x) - y;
eq.hyperbola = a + b / x - y;
solve x y / solveprint;
id a b;
run;


The printed output produced by this example consists of a model summary report, a listing of the solution values for each observation, and a solution summary report. The model summary for this example is shown in Figure 14.9.

 Supply-Demand Model using General-form Equations

 The MODEL Procedure

 Model Summary Model Variables 2 ID Variables 2 Equations 2 Number of Statements 2

 Model Variables x y Equations sqrt hyperbola

Figure 14.9: Model Summary Report

The output produced by the SOLVEPRINT option is shown in Figure 14.10.

 The MODEL Procedure Simultaneous Simulation

 Observation 1 a 0 b 1 eq.hyperbola 0.000000 Iterations 17 CC 0

 Solution Values x y 1.000000 1.000000

 Observation 2 a 1 b 1 eq.hyperbola 0.000000 Iterations 5 CC 0

 Solution Values x y 2.147899 1.465571

 Observation 3 a 1 b 2 eq.hyperbola 0.000000 Iterations 4 CC 0

 Solution Values x y 2.875130 1.695621

Figure 14.10: Solution Values for Each Observation

For each observation, a heading line is printed that lists the values of the ID variables for the observation and information on the iterative process used to compute the solution. Following the heading line for the observation, the solution values are printed.

The heading line shows the solution method used (Newton's method by default), the number of iterations required, and the convergence measure, labeled CC=. This convergence measure indicates the maximum error by which solution values fail to satisfy the equations. When this error is small enough (as determined by the CONVERGE= option), the iterations terminate. The equation with the largest error is indicated in parentheses. For example, for observation 3 the HYPERBOLA equation has an error of 4.42×10-13 while the error of the SQRT equation is even smaller.

The last part of the SOLVE statement output is the solution summary report shown in Figure 14.11. This report summarizes the iteration history and the model solved.

 The MODEL Procedure Simultaneous Simulation

 Data Set Options DATA= TEST

 Solution Summary Variables Solved 2 Implicit Equations 2 Solution Method NEWTON CONVERGE= 1E-8 Maximum CC 9.176E-9 Maximum Iterations 17 Total Iterations 26 Average Iterations 8.666667

 Observations Processed Read 3 Solved 3

 Variables Solved For x y Equations Solved sqrt hyperbola

Figure 14.11: Solution Summary Report

 Chapter Contents Previous Next Top