Create control dates in bilateral case crossover design

I am planning to study the effects of air pollution on emergency room visit and I intend to use a bilateral case crossover design. For each case (hospital visit) I would like to create 4 control dates (7 and 14 days before and after the visit). For instance, if a person visits a clinic on September 10, 2012 my controls will be Aug 27, Sep 03, Sep 17 and Sep 24. The following example illustrates what I have and what I want to achieve.

Any thought on how to undertake this in SAS, Stata or R would be highly appreciated

Sample data (all are visit dates)

id  date  
-------------
1   04-jan-05
2   05-jan-05
3   05-jan-05
4   06-jan-05
5   06-feb-05

What I would like to achieve (for each id there is one case and 4 controls)

id  date        outcome
---------------------------
1   21-Dec-04   control
1   28-Dec-04   control
1   04-Jan-05   case
1   11-Jan-05   control
1   18-Jan-05   control
2   22-Dec-04   control
2   29-Dec-04   control
2   05-Jan-05   case
2   12-Jan-05   control
2   19-Jan-05   control
3   22-Dec-04   control
3   29-Dec-04   control
3   05-Jan-05   case
3   12-Jan-05   control
3   19-Jan-05   control
4   23-Dec-04   control
4   30-Dec-04   control
4   06-Jan-05   case
4   13-Jan-05   control
4   20-Jan-05   control
5   23-Jan-05   control
5   30-Jan-05   control
5   06-Feb-05   case
5   13-Feb-05   control
5   20-Feb-05   control

Answers


A simple loop will produce the output you want.

data have;
input id  date :date10.;
format date date9.;
datalines;
1   04-jan-05
2   05-jan-05
3   05-jan-05
4   06-jan-05
5   06-feb-05
;
run;

data want (drop=i date rename=(date1=date));
set have;
format date1 date9.;
length outcome $8;
do i=-14 to 14 by 7;
    date1=date+i;
    outcome=ifc(i=0,'case','control');
    output;
end;
run;

Need Your Help

Fails to start LogMiner with PLS-00306

sql oracle11g

When I started LogMiner session with the following statements (in SQL*Plus with role sysdba) as copied from Oracle's tutorial Using LogMiner to Analyze Redo Log Files

Where does jquery code go in a partial view?

jquery html asp.net-mvc partial-views

I am brand new to asp.net MVC and JQuery. I've created a MVC site using the NerdDinner tutorial. For the create and edit views, I'm using a partial view (code simplified below) for data entry. W...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.