Hi SAS experts,
how to add the firm and year fixed effect in the PROC NLIN statement for the piecewise regression ? my current code does not have any fixed effect in the regression Xpart = a1 + b1*X; and Xpart = a1 + c*(b1-b2) + b2*X;. Thanks !
PROC NLIN DATA=local.plot2 MAXITER=1000 METHOD=MARQUARDT;
PARMS a1=1 b1=-2 c=3 b2=4 ;
Xpart = a1 + b1*X;
IF (X > c) THEN DO;
Xpart = a1 + c*(b1-b2) + b2*X;
end;
MODEL Y = Xpart;
OUTPUT OUT=PIECEFIT R=RESID P=PRED;
RUN;
* -- FIT THE POWER MODEL (FOR COMPARISON) USING NONLINEAR PROCEDURE -- *;
PROC NLIN DATA=local.plot2 MAXITER=1000 METHOD=MARQUARDT;
PARMS a=1 b1=2 b2=3;
MODEL Y = a1 + b1*X**b2;
OUTPUT OUT=POWERFIT R=PWR_RESID P=PWR_PRED;
RUN;
* -- COMBINE OUTPUT FROM BOTH MODELS -- *;
DATA ALL;
SET PIECEFIT POWERFIT;
RUN;
* -- PLOT DATA, PIECEWISE REGRESSION FIT, AND POWER MODEL FIT -- *;
SYMBOL1 f=marker v=U i=none c=blue;
SYMBOL2 v=none i=join line=1 w=3 c=blue;
SYMBOL3 v=none i=join line=2 w=3 c=black;
AXIS2 label = (a=90 r=0);
PROC GPLOT DATA=ALL;
PLOT Y*X=1 PRED*X=2 PWR_PRED*X=3 / OVERLAY FRAME VAXIS=AXIS2;
RUN;
Hi SAS experts,
how to add the fixed effect in the PROC NLIN statement for the piecewise regression ? my current code does not have any fixed effect in the regression Xpart = a1 + b1*X; and Xpart = a1 + c*(b1-b2) + b2*X;. Thanks !
PROC NLIN DATA=local.plot2 MAXITER=1000 METHOD=MARQUARDT;
PARMS a1=1 b1=-2 c=3 b2=4 ;
Xpart = a1 + b1*X;
IF (X > c) THEN DO;
Xpart = a1 + c*(b1-b2) + b2*X;
end;
MODEL Y = Xpart;
OUTPUT OUT=PIECEFIT R=RESID P=PRED;
RUN;
* -- FIT THE POWER MODEL (FOR COMPARISON) USING NONLINEAR PROCEDURE -- *;
PROC NLIN DATA=local.plot2 MAXITER=1000 METHOD=MARQUARDT;
PARMS a=1 b1=2 b2=3;
MODEL Y = a1 + b1*X**b2;
OUTPUT OUT=POWERFIT R=PWR_RESID P=PWR_PRED;
RUN;
* -- COMBINE OUTPUT FROM BOTH MODELS -- *;
DATA ALL;
SET PIECEFIT POWERFIT;
RUN;
* -- PLOT DATA, PIECEWISE REGRESSION FIT, AND POWER MODEL FIT -- *;
SYMBOL1 f=marker v=U i=none c=blue;
SYMBOL2 v=none i=join line=1 w=3 c=blue;
SYMBOL3 v=none i=join line=2 w=3 c=black;
AXIS2 label = (a=90 r=0);
PROC GPLOT DATA=ALL;
PLOT Y*X=1 PRED*X=2 PWR_PRED*X=3 / OVERLAY FRAME VAXIS=AXIS2;
RUN;
It's not clear to me what you mean with "adding a fixed effect"?
[EDIT] Also better to move this topic thread to the "Statistical Procedures" board!
Analytics (header) > Statistical procedures.
Can someone with superpowers do so?
Thanks,
Koen
Hi Koen,
Thank you very much for your reply. My code is not giving errors but not doing what I want. I would like to add firm and year fixed effect in the regression. Currently, I only have explanatory variable x in the regression. I'm not sure how to include firm and year fixed effect in the proc nlin process.
Hello @Nieves ,
I think you just have to add FIRM and YEAR to Xpart = (both Xpart-s!).
But it seems you are doing econometrics and having panel data (time series cross-sectional) data.
For panel data (and for having correct parameter estimation methods for non-independent observations and clusters in the data), there is PROC MIXED (or PROC GLIMMIX), PROC PANEL, PROC TSCSREG and PROC CPANEL (SAS VIYA Econometrics).
But these 4 procedures do not allow for the segmented regression (broken-stick regression) you are aiming at.
Segmented regression (Segmented Models) is also known as 'broken-stick regression' or 'Change Point Models'.
You can also use PROC MCMC (Markov chain Monte Carlo) for 'Change Point Models'. See the doc for PROC MCMC.
I hope you can sort it out.
Kind regards,
Koen
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.