title2 "Price Unitcost Solution"; /* produce goal-seeking solutions for income and quantity assumptions*/ proc model model=model; solve price unitcost / data=goal out=pc; run; proc print
Trang 1Output 18.6.3 Listing of OUTEST= Data Set Created in the FIT Statement
General Form Equations for Supply-Demand Model
Price Quantity Solution _
1 2SLS 0 Converged 10 -395.887 0.71733 0.29806 -107.620 201.571 102.212
Output 18.6.4 Listing of OUT= Data Set Created in the First SOLVE Statement
General Form Equations for Supply-Demand Model
Price Quantity Solution
Obs _TYPE_ _MODE_ _ERRORS_ price quantity income unitcost year
1 PREDICT SIMULATE 0 1.20473 371.552 2571.87 2.31220 1986
2 PREDICT SIMULATE 0 1.18666 382.642 2609.12 2.45633 1987
3 PREDICT SIMULATE 0 1.20154 391.788 2639.77 2.51647 1988
4 PREDICT SIMULATE 0 1.68089 400.478 2667.77 1.65617 1989
5 PREDICT SIMULATE 0 2.06214 411.896 2705.16 1.01601 1990
The following statements produce the goal-seeking solutions for PRICE and UNITCOST by using the GOAL dataset
title2 "Price Unitcost Solution";
/* produce goal-seeking solutions for
income and quantity assumptions*/
proc model model=model;
solve price unitcost / data=goal out=pc;
run;
proc print data=pc;
run;
The output data set produced by the final SOLVE statement is shown inOutput 18.6.5
Trang 2Output 18.6.5 Listing of OUT= Data Set Created in the Second SOLVE Statement
General Form Equations for Supply-Demand Model
Price Unitcost Solution Obs _TYPE_ _MODE_ _ERRORS_ price quantity income unitcost year
1 PREDICT SIMULATE 0 0.99284 371.4 2571.87 2.72857 1986
2 PREDICT SIMULATE 0 1.86594 416.5 2721.08 1.44798 1987
3 PREDICT SIMULATE 0 2.12230 597.3 3327.05 2.71130 1988
4 PREDICT SIMULATE 0 2.46166 764.1 3885.85 3.67395 1989
5 PREDICT SIMULATE 0 2.74831 694.3 3650.98 2.42576 1990
Example 18.7: Spring and Damper Continuous System
This model simulates the mechanical behavior of a spring and damper system shown inFigure 18.92
Figure 18.92 Spring and Damper System Model
A mass is hung from a spring with spring constant K The motion is slowed by a damper with damper constant C The damping force is proportional to the velocity, while the spring force is proportional
to the displacement
This is actually a continuous system; however, the behavior can be approximated by a discrete time model We approximate the differential equation
@ d i sp
@ t i me D velocity
Trang 3with the difference equation
d i sp
t i me D velocity
This is rewritten as
d i sp LAG.d i sp/
where dt is the time step used In PROC MODEL, this is expressed with the program statement
disp = lag(disp) + vel * dt;
or
dert.disp = vel;
The first statement is simply a computing formula for Euler’s approximation for the integral
d i spD
Z veloci ty dt
If the time step is small enough with respect to the changes in the system, the approximation is good Although PROC MODEL does not have the variable step-size and error-monitoring features of simulators designed for continuous systems, the procedure is a good tool to use for less challenging continuous models
The second form instructs the MODEL procedure to do the integration for you
This model is unusual because there are no exogenous variables, and endogenous data are not needed Although you still need a SAS data set to count the simulation periods, no actual data are brought in Since the variables DISP and VEL are lagged, initial values specified in the VAR statement determine the starting state of the system The mass, time step, spring constant, and damper constant are declared and initialized by a CONTROL statement as shown in the following statements:
title1 'Simulation of Spring-Mass-Damper System';
/*- Data to drive the simulation time periods -*/
data one;
do n=1 to 100;
output;
end;
run;
proc model data=one outmodel=spring;
var force -200 disp 10 vel 0 accel -20 time 0;
force = -k * disp -c * vel;
disp = lag(disp) + vel * dt;
Trang 4vel = lag(vel) + accel * dt;
accel = force / mass;
time = lag(time) + dt;
run;
The displacement scale is zeroed at the point where the force of gravity is offset, so the acceleration
of the gravity constant is omitted from the force equation The control variable C and K represent the damper and the spring constants respectively
The model is simulated three times, and the simulation results are written to output data sets The first run uses the original initial conditions specified in the VAR statement In the second run, the initial displacement is doubled; the results show that the period of the motion is unaffected by the amplitude In the third run, the DERT syntax is used to do the integration Notice that the path of the displacement is close to the old path, indicating that the original time step is short enough to yield an accurate solution These simulations are performed by the following statements:
proc model data=one model=spring;
title2 "Simulation of the model for the base case";
control run '1';
solve / out=a;
run;
title2 "Simulation of the model with twice the initial displacement"; control run '2';
var disp 20;
solve / out=b;
run;
data two;
do time = 0 to 10 by 2; output;end;
run;
title2 "Simulation of the model using the dert syntax";
proc model data=two;
var force -200 disp 10 vel 0 accel -20 time 0;
control run '3' ;
force = -k * disp -c * vel;
dert.disp = vel ;
dert.vel = accel;
accel = force / mass;
solve / out=c;
id time ;
run;
The output SAS data sets that contain the solution results are merged and the displacement time paths for the three simulations are plotted The three runs are identified on the plot as 1, 2, and 3 The following statements produceOutput 18.7.1throughOutput 18.7.5
data p;
set a b c;
run;
Trang 5title2 'Overlay Plot of All Three Simulations';
proc sgplot data=p;
series x=time y=disp / group=run lineattrs=(pattern=1);
xaxis values=(0 to 10 by 1);
yaxis values=(-20 to 20 by 10);
run;
Output 18.7.1 Model Summary
Simulation of Spring-Mass-Damper System Simulation of the model for the base case
The MODEL Procedure
Model Summary
Model Variables 5 Control Variables 5
Number of Statements 6 Program Lag Length 1
Model Variables force(-200) disp(10) vel(0) accel(-20) time(0) Control Variables mass(9.2) c(1.5) dt(0.1) k(20) run(1)
Equations force disp vel accel time
Output 18.7.2 Printed Output Produced by PROC MODEL SOLVE Statements
Simulation of Spring-Mass-Damper System Simulation of the model for the base case
The MODEL Procedure Dynamic Simultaneous Simulation
Data Set Options
DATA= ONE
Solution Summary
Simulation Lag Length 1 Solution Method NEWTON
Trang 6Output 18.7.2 continued
Observations Processed
Solved 99
Variables Solved For force disp vel accel time
Output 18.7.3 Printed Output Produced by PROC MODEL SOLVE Statements
Simulation of Spring-Mass-Damper System Simulation of the model with twice the initial displacement
The MODEL Procedure Dynamic Simultaneous Simulation
Data Set Options
DATA= ONE
Solution Summary
Simulation Lag Length 1 Solution Method NEWTON
Observations Processed
Solved 99
Variables Solved For force disp vel accel time
Trang 7Output 18.7.4 Printed Output Produced by PROC MODEL SOLVE Statements
Simulation of Spring-Mass-Damper System Simulation of the model using the dert syntax
The MODEL Procedure Simultaneous Simulation
Data Set Options
DATA= TWO
Solution Summary
Solution Method NEWTON Maximum Iterations 0
Observations Processed
Solved 51
Variables Solved For force disp vel accel
Auxiliary Equations force accel
Trang 8Output 18.7.5 Overlay Plot of Three Simulations
Example 18.8: Nonlinear FIML Estimation
The data and model for this example were obtained from Bard (1974, p.133–138) The example is a two-equation econometric model used by Bodkin and Klein to fit U.S production data for the years 1909–1949 The model is the following:
g1D c110c2 z 4.c5z c4
1 C 1 c5/z c4
2 / c3 =c 4 z3D 0
g2D Œc5=.1 c5/.z1=z2/ 1 c4 / z5D 0 where z1is capital input, z2is labor input, z3is real output, z4is time in years with 1929 as year zero, and z5is the ratio of price of capital services to wage scale The ci’s are the unknown parameters z1 and z2are considered endogenous variables A FIML estimation is performed by using the following statements:
Trang 9data bodkin;
input z1 z2 z3 z4 z5;
datalines;
1.33135 0.64629 0.4026 -20 0.24447
1.39235 0.66302 0.4084 -19 0.23454
more lines
title1 "Nonlinear FIML Estimation";
proc model data=bodkin;
parms c1-c5;
endogenous z1 z2;
exogenous z3 z4 z5;
eq.g1 = c1 * 10 **(c2 * z4) * (c5*z1**(-c4)+
(1-c5)*z2**(-c4))**(-c3/c4) - z3;
eq.g2 = (c5/(1-c5))*(z1/z2)**(-1-c4) -z5;
fit g1 g2 / fiml ;
run;
When FIML estimation is selected, the log likelihood of the system is output as the objective value The results of the estimation are shown inOutput 18.8.1
Output 18.8.1 FIML Estimation Results for U.S Production Data
Nonlinear FIML Estimation
The MODEL Procedure
Nonlinear FIML Summary of Residual Errors
Equation Model Error SSE MSE Root MSE R-Square R-Sq
Nonlinear FIML Parameter Estimates
Parameter Estimate Std Err t Value Pr > |t|
Trang 10Output 18.8.1 continued
Number of Observations Statistics for System
Example 18.9: Circuit Estimation
Consider the nonlinear circuit shown inFigure 18.93
Figure 18.93 Nonlinear Resistor Capacitor Circuit
The theory of electric circuits is governed by Kirchhoff’s laws: the sum of the currents flowing to a node is zero, and the net voltage drop around a closed loop is zero In addition to Kirchhoff’s laws, there are relationships between the current I through each element and the voltage drop V across the elements For the circuit inFigure 18.93, the relationships are
Cd V
dt D I
for the capacitor and
V D R1C R2.1 exp V///I
for the nonlinear resistor The following differential equation describes the current at node 2 as a function of time and voltage for this circuit:
Cd V2
dt
V1 V2
R1C R2.1 exp V// D 0 This equation can be written in the form
d V2
.R1C R2.1 exp V///C