|
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 supply and demand 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(where=(eec ne .));
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 . That is, you want to solve the system:
The following statements read parameters for several hyperbolas in the input data set TEST and solve the nonlinear equations. The SOLVEPRINT option in 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.
title1 'Solving a Simultaneous System';
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 19.9.
Figure 19.9
Model Summary Report
The output produced by the SOLVEPRINT option is shown in Figure 19.10.
Figure 19.10
Solution Values for Each Observation
The MODEL Procedure
Simultaneous Simulation
1 |
0 |
1.0000 |
0.000000 |
|
17 |
0.000000 |
|
2 |
1.0000 |
1.0000 |
0.000000 |
|
5 |
0.000000 |
|
3 |
1.0000 |
2.0000 |
0.000000 |
|
4 |
0.000000 |
|
For each observation, a heading line is printed that lists the values of the ID variables for the observation and information about the iterative process used to compute the solution. The number of iterations required, and the convergence measure (labeled CC) are printed. 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. For example, for observation 3 the HYPERBOLA equation has an error of while the error of the SQRT equation is even smaller. Following the heading line for the observation, the solution values are printed.
The last part of the SOLVE statement output is the solution summary report shown in Figure 19.11. This report summarizes the solution method used (Newton’s method by default), the iteration history, and the observations processed.
Figure 19.11
Solution Summary Report
The MODEL Procedure
Simultaneous Simulation
2 |
2 |
NEWTON |
1E-8 |
9.176E-9 |
17 |
26 |
8.666667 |