BookmarkSubscribeRSS Feed
hkim3677
Calcite | Level 5

Hi, 

 

I am working on my research project and have been struggling with assign 1 for post-treatment group.

 

for example,

Data test;
input ID YEAR TURNOVER;
datalines;
1 1990 0
1 1991 0
1 1992 1
1 1993 0
1 1994 0
1 1995 1
1 1996 0
1 1997 0
2 1993 0
2 1994 0
2 1995 0
2 1996 1
2 1997 0
2 1998 0
2 1999 0
2 2000 0

2 2001 0

;
run;

 

In this case,  we have two firms and each firm has one or two turnover event. The problem that I need to solve is how to create the "Post_Turnover" by each firm. If the firm has two turnovers, the overlapped period between first and second turnover is needed to be duplicated and set "Post_Turnover"  = 1 to half of the duplicated observations.

 

Please help me this code!

 

Thank you!

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

what should the output look like?

hkim3677
Calcite | Level 5

 

The dataset should look like...


ID YEAR TURNOVER Post_Turnover;
1 1990 0 0
1 1991 0 0
1 1992 1 1
1 1993 0 1
1 1994 0 1

1 1993 0 0
1 1994 0 0

1 1995 1 1
1 1996 0 1
1 1997 0 1
2 1993 0 0
2 1994 0 0
2 1995 0 0
2 1996 1 1
2 1997 0 1
2 1998 0 1
2 1999 0 1
2 2000 0 1

2 2001 0 1

 

The following two observations were duplicated for pre-treatment for the second turnover since this period is between two turnovers.
1 1993 0 0
1 1994 0 0

 

Thank you!

 

ChrisNZ
Tourmaline | Level 20

Like this?

 

data HAVE;
  input ID YEAR TURNOVER;
datalines;
1 1990 0
1 1991 0
1 1992 1
1 1993 0
1 1994 0
1 1995 1
1 1996 0
1 1997 0
2 1993 0
2 1994 0
2 1995 0
2 1996 1
2 1997 0
2 1998 0
2 1999 0
2 2000 0
2 2001 0
run;
data WANT;
  retain TURNOVER_YEAR POST_TURNOVER;
  set HAVE;
  by ID;
  if first.ID then POST_TURNOVER=0;
  if TURNOVER and POST_TURNOVER=1 then do;
    TMPYEAR=YEAR; 
    POST_TURNOVER=0;
    do YEAR=TURNOVER_YEAR+1 to TMPYEAR-1; 
      POST_TURNOVER=0; 
      output;
    end;
    YEARTMP=YEAR; 
    POST_TURNOVER=1;
  end;
  else if TURNOVER then do; 
    POST_TURNOVER =1; 
    TURNOVER_YEAR =YEAR;
  end;
  output;
  keep ID YEAR TURNOVER POST_TURNOVER;
run;

 

POST_TURNOVER ID YEAR TURNOVER
0 1 1990 0
0 1 1991 0
1 1 1992 1
1 1 1993 0
1 1 1994 0
0 1 1993 1
0 1 1994 1
1 1 1995 1
1 1 1996 0
1 1 1997 0
0 2 1993 0
0 2 1994 0
0 2 1995 0
1 2 1996 1
1 2 1997 0
1 2 1998 0
1 2 1999 0
1 2 2000 0
1 2 2001 0
hkim3677
Calcite | Level 5

Thank you! However,.... Now I realized that I mis-specified turnover value. Can you help me find the turnover event? Like...

ID YEAR Manager Turnover

1 1990 a 0

1 1991 a 0

1 1992 b 1

1 1993 b 0

1 1994 b 0

1 1995 c 1

1 1996 c 0

1 1997 c 0

2 1993 d 0

2 1994 d 0

2 1995 d 0

2 1996 e 1

2 1997 e 0

2 1998 e 0

2 1999 e 0

2 2000 e 0

2 2001 e 0

 

Can you help me create the turnover column?

 

I really appreciate your help!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 955 views
  • 0 likes
  • 2 in conversation