Testing Difference in Mean Between Two Specific Periods

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Testing Difference in Mean Between Two Specific Periods

Hi,

 

I am trying to test if the mean of two variables differ within two specific periods.

 

Precisely, I want to test if the mean of RSP differs in the period: 25Jan2002 through 24Feb2003, compared to the period: 25Feb2003 through 26Mar2004.

 

I tried to create a 'flag' variable to distinguish both time periods. However, my log files suggests that the 'CLASS variable does not have two levels'. I am not too sure why the class flag variable does not have two levels as I have enough observations within the specified periods.

 

 

 

See my codes:

 

data xx;
set x;

Startdate = '25Jan2002'd < '24Feb2003'd < '24Feb2003'd;
Enddate = '25Feb2003'd < '24Feb2003'd < '26Mar2004'd;

If Startdate <= '24Feb2003'd <= Enddate then flag=1;
else flag = 0;
run;

 

proc ttest data=xx;
class flag;
var RSP;

run;
run;

 

 

 

Log File:

data xx;
set x;
Startdate = '25Jan2002'd < '24Feb2003'd < '24Feb2003'd;
Enddate = '24Feb2003'd < '24Feb2003'd < '26Mar2004'd;

If Startdate <= '24Feb2003'd <= Enddate then flag=1;
else flag = 0;

run;

NOTE: There were 6179 observations read from the data set WORK.SPVIXTWO.
NOTE: The data set WORK.SPVIXTWOX has 6179 observations and 34 variables.


proc ttest data=xx;
class flag;
var VarRSP20;
run;

ERROR: The CLASS variable does not have two levels.

 

 

 

Is there an alternative way to do this or are my codes wrong? I would be glad to provide clarifications where necessary.

 

Thank you in anticipation!


Accepted Solutions
Solution
‎03-25-2018 01:07 PM
Respected Advisor
Posts: 3,061

Re: Testing Difference in Mean Between Two Specific Periods

You need to use your date variable to determine the flags, but you haven't done that.

 

For example if the variable that contains the date in data set x is named DATE, then

If '25jan2002'd<date<'24feb2003'd then flag=1;

 

--
Paige Miller

View solution in original post


All Replies
Solution
‎03-25-2018 01:07 PM
Respected Advisor
Posts: 3,061

Re: Testing Difference in Mean Between Two Specific Periods

You need to use your date variable to determine the flags, but you haven't done that.

 

For example if the variable that contains the date in data set x is named DATE, then

If '25jan2002'd<date<'24feb2003'd then flag=1;

 

--
Paige Miller
Contributor
Posts: 33

Re: Testing Difference in Mean Between Two Specific Periods

Posted in reply to PaigeMiller

Thank you!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 152 views
  • 2 likes
  • 2 in conversation