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); /* -------- Demand equation ------------- */ eq.demand = eec - (b1 + b2 * eegp + b3 * cciutc); /* -------- 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 26.9.
Figure 26.9: Model Summary Report
The output produced by the SOLVEPRINT option is shown in Figure 26.10.
Figure 26.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 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 26.11. This report summarizes the solution method used (Newton’s method by default), the iteration history, and the observations processed.
Figure 26.11: Solution Summary Report