BookmarkSubscribeRSS Feed
r4321
Pyrite | Level 9

Hello all,

 

Updating the description of the code I am hoping to get help with: 

 

I have a dataset where I am hoping to indicator variables that help me better organize a matched sample from my data. I have data on counties observed each week over the course of a year, some of them experienced a focal event (i.e., if P =1) and some did not and will serve as controls. Additionally, some counties experienced the focal event more than once. I want to add an indicator variable that identifies before and after these focal events at different durations for both the treatments and the non-treated counties. I need at 1 week, 2 weeks, 3 weeks, 4 weeks, and 5 weeks, but only illustrated up to 2 weeks in the example below. 

 

In addition, would be ideal if once a county experienced a focal event they can no longer be in the control set from there forward, but it’s okay if they stay in the dataset and experience a focal event again.

 

I believe I need some variables such as an eventweek variable that identifies the week of the focal event, a before/after variable (0/1 if before after the focal event), a duration variable that identifies the number of weeks before and after (i.e., at 1, 2, 3, 4, and 5), and a variable (treated) that indicates that a county has been treated (after it has been treated since a county should be able to stay in the pool of controls to serve as a control until it gets treated if at all).

 

Essentially, I think I need to duplicate sets of observations to create windows of treated and non-treated counties around the focal events I am interested in examining. I also like to add a few other variables: (1) a variable that indicates which treatment number this is for a county (i.e., first treatment, second treatment, …) (2) a variable that indicates whether a county was treated within a short time window of a previous time it was treated (=1 if treated within <=5 time periods, 0 otherwise) and (3) a variable that indicates the degree of treatment (I want focal event variable to be binary in the wantdata but in the have data it is a actually >1 sometimes since it is a count variable), so if focal event was 2, for example, this variable would = 2. See below for example.

 

Also, I should note that is a focal occurred before week 6, the durations for those observations may not be able to get up to the full 5 weeks before and after. For example, if a focal event occurred in a county in week 2, I'll only have the 1 week duration for that focal event. 

 

Thanks!

 

 

 

Have:

 

Time

ID

County

FocalEvent

1

222

ABC

0

2

222

ABC

0

3

222

ABC

0

4

222

ABC

0

5

222

ABC

1

6

222

ABC

0

7

222

ABC

0

8

222

ABC

0

9

222

ABC

0

10

222

ABC

0

11

222

ABC

0

12

222

ABC

0

13

222

ABC

0

1

333

BBB

0

2

333

BBB

0

3

333

BBB

0

4

333

BBB

0

5

333

BBB

0

6

333

BBB

0

7

333

BBB

0

8

333

BBB

0

9

333

BBB

0

10

333

BBB

0

11

333

BBB

0

12

333

BBB

0

13

333

BBB

0

1

444

CCC

0

2

444

CCC

0

3

444

CCC

0

4

444

CCC

0

5

444

CCC

1

6

444

CCC

0

7

444

CCC

0

8

444

CCC

0

9

444

CCC

0

10

444

CCC

1

11

444

CCC

0

12

444

CCC

0

13

444

CCC

0

1

555

DDD

0

2

555

DDD

0

3

555

DDD

0

4

555

DDD

0

5

555

DDD

0

6

555

DDD

0

7

555

DDD

0

 

 

Want:

 

Time

ID

County

FocalEvent

EventWeek

Duration

BeforeAfter

Treated

Tnumber

Trecent

Tdegree

4

222

ABC

0

5

1

0

1

1

0

0

5

222

ABC

1

5

1

1

1

1

0

0

4

333

BBB

0

5

1

0

0

0

0

0

5

333

BBB

0

5

1

1

0

0

0

0

4

444

CCC

0

5

1

0

1

1

0

0

5

444

CCC

1

5

1

1

1

1

0

0

4

555

DDD

0

5

1

0

0

0

0

0

5

555

DDD

0

5

1

1

0

0

0

0

9

444

CCC

0

10

1

0

1

2

0

0

10

444

CCC

1

10

1

1

1

2

0

0

9

333

BBB

0

10

1

0

0

0

0

0

10

333

BBB

0

10

1

1

0

0

0

0

3

222

ABC

0

5

2

0

1

1

0

0

4

222

ABC

0

5

2

0

1

1

0

0

5

222

ABC

1

5

2

1

1

1

0

0

6

222

ABC

0

5

2

1

1

1

0

0

3

333

BBB

0

5

2

0

0

0

0

0

4

333

BBB

0

5

2

0

0

0

0

0

5

333

BBB

0

5

2

1

0

0

0

0

6

333

BBB

0

5

2

1

0

0

0

0

3

444

CCC

0

5

2

0

1

1

0

0

4

444

CCC

0

5

2

0

1

1

0

0

5

444

CCC

1

5

2

1

1

1

0

0

6

444

CCC

0

5

2

1

1

1

0

0

3

555

DDD

0

5

2

0

0

0

0

0

4

555

DDD

0

5

2

0

0

0

0

0

5

555

DDD

0

5

2

1

0

0

0

0

6

555

DDD

0

5

2

1

0

0

0

0

8

444

CCC

0

10

1

0

1

2

0

0

9

444

CCC

0

10

1

0

1

2

0

0

10

444

CCC

1

10

1

1

1

2

0

0

11

444

CCC

1

10

1

1

1

2

0

0

8

333

BBB

0

10

1

0

0

0

0

0

9

333

BBB

0

10

1

0

0

0

0

0

10

333

BBB

0

10

1

1

0

0

0

0

11

333

BBB

0

10

1

1

0

0

0

0

 

 

 

 

1 REPLY 1
r4321
Pyrite | Level 9
Updated the question

Thanks,

Rich

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 640 views
  • 0 likes
  • 1 in conversation