Page 1 of 1

How do I hide coeffs with zero restrictions in output?

Posted: Thu Jul 16, 2015 3:21 pm
by macro
I have a program that uses RESTRICT to impose zero restrictions on the coefficients from a LINREG instruction. The restrictions are imposed in a loop and aren't known at run time, so I can't manually specify the cards for the LINREG or RESTRICT instructions. I want to impose zero restrictions on certain coefficients and hide those coefficients from the output (since they're dropped from the model, in essence). Here is some example code:

Code: Select all

calendar(q) 1959 1
allocate 50 2019:4

open data nipa.csv
data(format=cdf,org=columns) 1959:1 2015:1 gdp pce
close data

linreg(print) gdp / 
# pce{1 to 4} constant

restrict(create, print) 1
# 2
# 1 0
The RESTRICT instruction outputs this:

Code: Select all

restrict(create) 1
# 2
# 1 0
t(216)=   0.736763 or F(1,216)=   0.542819 with Significance Level 0.46206623


Linear Model - Estimation by Restricted Regression
Dependent Variable GDP
Quarterly Data From 1960:01 To 2015:01
Usable Observations                       221
Degrees of Freedom                        217
Mean of Dependent Variable       8863.9378733
Std Error of Dependent Variable  4048.9644051
Standard Error of Estimate        592.0039366
Sum of Squared Residuals         76051699.429
Durbin-Watson Statistic                0.0928

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PCE{1}                           4.527779     0.700730      6.46152  0.00000000
2.  PCE{2}                           0.000000     0.000000      0.00000  0.00000000
3.  PCE{3}                           0.167976     1.677421      0.10014  0.92032590
4.  PCE{4}                          -3.685333     1.227224     -3.00298  0.00298715
5.  Constant                      4077.829482    65.287299     62.45977  0.00000000
whereas I want it to output this:

Code: Select all

restrict(create) 1
# 2
# 1 0
t(216)=   0.736763 or F(1,216)=   0.542819 with Significance Level 0.46206623


Linear Model - Estimation by Restricted Regression
Dependent Variable GDP
Quarterly Data From 1960:01 To 2015:01
Usable Observations                       221
Degrees of Freedom                        217
Mean of Dependent Variable       8863.9378733
Std Error of Dependent Variable  4048.9644051
Standard Error of Estimate        592.0039366
Sum of Squared Residuals         76051699.429
Durbin-Watson Statistic                0.0928

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  PCE{1}                           4.527779     0.700730      6.46152  0.00000000
2.  PCE{3}                           0.167976     1.677421      0.10014  0.92032590
3.  PCE{4}                          -3.685333     1.227224     -3.00298  0.00298715
4.  Constant                      4077.829482    65.287299     62.45977  0.00000000
Note that I've simply deleted the PCE{2} coefficient because a zero restriction was imposed on it. Is this possible? The file containing the data is attached.

Re: How do I hide coeffs with zero restrictions in output?

Posted: Thu Jul 16, 2015 3:49 pm
by TomDoan
Is the RESTRICT being used simply to knock variables out of the regressor list? In other words, would it accomplish what you need to simply rewrite the regressor list to exclude them and then do a LINREG on the reduced set of regressors?

Re: How do I hide coeffs with zero restrictions in output?

Posted: Thu Jul 16, 2015 5:19 pm
by macro
Yes, RESTRICT is being used to knock out coefficients. I can't manually rewrite the cards for the LINREG instruction, though, because the coefficient that gets knocked out isn't known at runtime; it's determined to be a different coefficient on each iteration of the loop. If there is a way to run a LINREG instruction, get the regressor list (I know that can be done with %reglist()), then remove a coefficient from that list and pass that list back into a new LINREG instruction, that should accomplish what I'm trying to do.

Re: How do I hide coeffs with zero restrictions in output?

Posted: Fri Jul 17, 2015 10:57 am
by TomDoan
What you use are the %TABLE... functions to alter the list of variables, this convert that into a regressor list at the end with %RLFROMTABLE. This, for instance, would knock out the second coefficient.

Code: Select all

linreg(print) gdp
# pce{1 to 4} constant
*
compute etable=%eqntable(0)
dec vect[int] keep(4)
ewise keep(i)=%if(i<2,i,i+1)
linreg(print) gdp
# %rlfromtable(%tableextract(etable,keep))
Depending upon how you're determining the regressors to pull out, you might find %TABLEFIND and %TABLEFINDMISS to be useful instead of %TABLEEXTRACT.

Re: How do I hide coeffs with zero restrictions in output?

Posted: Fri Jul 17, 2015 4:47 pm
by macro
The combination of %rlfromtable and %tableextract is exactly what I was looking for. Also, I didn't realize that the output from regression list functions could be passed directly into LINREG as a card. Thank you!