BookmarkSubscribeRSS Feed
littlewho
Fluorite | Level 6

Hello,

I am trying to run a 2nd degree regression on a dataset looking like the following:

 

datereturnscontinuous_datecontinuous_dateSquared

1

2007Q4-0.532007.754031060.0625
22008Q1-5.1120084032064
32008Q2-3.1766666672008.254033068.0625
42008Q3-1.5166666672008.54034072.25
52008Q4-6.572008.754035076.5625
62009Q1-8.49520094036081
72009Q20.10666666672009.254037085.5625
82009Q36.4752009.54038090.25
92009Q412.722009.754039095.0625
102010Q11.26520104040100
112010Q2-0.1252010.254041105.0625
122010Q30.5652010.54042110.25
132010Q42.4952010.754043115.5625

 

 

The regression equation should be like the following: Returns(t) = a + b * time(t) + c * time(t)^2 and the code looks like this:

proc reg data=temp;
   model returns=continuous_date continuous_dateSquared;
   ods output ParameterEstimates=params;
run;

When I try to run this, I'm getting the following error:

Screenshot from 2020-07-08 12-46-12.png

That's strange, because using the regression option from sgplot, works just fine:

ods graphics / reset width=8in height=6in imagemap;
proc sgplot data=temp;
	reg x=continuous_date y=returns_avg / degree=2 nomarkers; 
	scatter x=continuous_date y=returns_avg; 
run;
ods graphics / reset;
title;

Could anyone point what I am doing wrong?

Thanks!

3 REPLIES 3
ballardw
Super User

Note that your SGPLOT does not include the squared date.

Also see the parameter for continuous_dateSquared of zero? Meaning that the parameter is not actually used:

 

y= ax**2 + bx + c is the same as y=bx+c when a=0.

 

Not that reg is the best tool but the magnitude of the values for your "dates" are pretty large compared to the values of returns and the squared version is doing about what I would expect because of the magnitude.

You might see something marginally more useful if subtract something like 2006 from "continuous_date" and then square that value (which will yield values more in the range of 1.5 to 100 instead of 4,000,000). So "continuous date" would interpret as "year from 2006" instead of the absolute year.

littlewho
Fluorite | Level 6

@ballardw wrote:

Note that your SGPLOT does not include the squared date.


I included the option "degree=2" in the sgplot reg instruction, shouldn't be this the way of including the squared date?

 

Thanks for the suggestion, I will try to rescale the parameters and see what I would get.

smantha
Lapis Lazuli | Level 10

I see the following warnings in the code that supports Ballard's hypotheses


@littlewho wrote:

Hello,

I am trying to run a 2nd degree regression on a dataset looking like the following:

 

date returns continuous_date continuous_dateSquared

1

2007Q4 -0.53 2007.75 4031060.0625
2 2008Q1 -5.11 2008 4032064
3 2008Q2 -3.176666667 2008.25 4033068.0625
4 2008Q3 -1.516666667 2008.5 4034072.25
5 2008Q4 -6.57 2008.75 4035076.5625
6 2009Q1 -8.495 2009 4036081
7 2009Q2 0.1066666667 2009.25 4037085.5625
8 2009Q3 6.475 2009.5 4038090.25
9 2009Q4 12.72 2009.75 4039095.0625
10 2010Q1 1.265 2010 4040100
11 2010Q2 -0.125 2010.25 4041105.0625
12 2010Q3 0.565 2010.5 4042110.25
13 2010Q4 2.495 2010.75 4043115.5625

 

 

The regression equation should be like the following: Returns(t) = a + b * time(t) + c * time(t)^2 and the code looks like this:

proc reg data=temp;
   model returns=continuous_date continuous_dateSquared;
   ods output ParameterEstimates=params;
run;

When I try to run this, I'm getting the following error:

Screenshot from 2020-07-08 12-46-12.png

That's strange, because using the regression option from sgplot, works just fine:

ods graphics / reset width=8in height=6in imagemap;
proc sgplot data=temp;
	reg x=continuous_date y=returns_avg / degree=2 nomarkers; 
	scatter x=continuous_date y=returns_avg; 
run;
ods graphics / reset;
title;

Could anyone point what I am doing wrong?

Thanks!



@littlewho wrote:

Hello,

I am trying to run a 2nd degree regression on a dataset looking like the following:

 

date returns continuous_date continuous_dateSquared

1

2007Q4 -0.53 2007.75 4031060.0625
2 2008Q1 -5.11 2008 4032064
3 2008Q2 -3.176666667 2008.25 4033068.0625
4 2008Q3 -1.516666667 2008.5 4034072.25
5 2008Q4 -6.57 2008.75 4035076.5625
6 2009Q1 -8.495 2009 4036081
7 2009Q2 0.1066666667 2009.25 4037085.5625
8 2009Q3 6.475 2009.5 4038090.25
9 2009Q4 12.72 2009.75 4039095.0625
10 2010Q1 1.265 2010 4040100
11 2010Q2 -0.125 2010.25 4041105.0625
12 2010Q3 0.565 2010.5 4042110.25
13 2010Q4 2.495 2010.75 4043115.5625

 

 

The regression equation should be like the following: Returns(t) = a + b * time(t) + c * time(t)^2 and the code looks like this:

proc reg data=temp;
   model returns=continuous_date continuous_dateSquared;
   ods output ParameterEstimates=params;
run;

When I try to run this, I'm getting the following error:

Screenshot from 2020-07-08 12-46-12.png

That's strange, because using the regression option from sgplot, works just fine:

ods graphics / reset width=8in height=6in imagemap;
proc sgplot data=temp;
	reg x=continuous_date y=returns_avg / degree=2 nomarkers; 
	scatter x=continuous_date y=returns_avg; 
run;
ods graphics / reset;
title;

Could anyone point what I am doing wrong?

Thanks!


WARNING: The range of variable cont_date is so small relative to its mean that there may be loss of accuracy in the computations.
You may need to rescale the variable to have a larger value of RANGE/abs(MEAN), for example, by using PROC STANDARD M=0;
WARNING: The range of variable cont_date_sq is so small relative to its mean that there may be loss of accuracy in the
computations. You may need to rescale the variable to have a larger value of RANGE/abs(MEAN), for example, by using PROC
STANDARD M=0;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1238 views
  • 0 likes
  • 3 in conversation