trading days between dates

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

trading days between dates

Geoffrey Smith-3
Hello, I have some unbalanced panel data that is measured on weekdays only
(i.e., excluding Saturday and Sunday).  I would like to get the number of
trading days between dates such that the number of days between a Friday and
a Monday is 1 (and not 3).  Here is some code to illustrate my problem:

library('Hmisc');

DATE <- as.Date(c('2011-05-18','2011-05-19','2011-05-20','2011-05-
23','2011-05-24','2011-05-25','2011-05-27'), '%Y-%m-%d');
PRCS <- c(100,105,110,95,90,85,95);
DAYS <- weekdays(DATE);

DF <- data.frame(DATE, PRCS, DAYS);
DF;

DF$DAYS.BETWEEN <- DF$DATE - Lag(DF$DATE);
DF;

Essentially, I want to get it so the variable DAYS.BETWEEN is equal to 1 for
observation number 4, but still be equal to 2 for observation number 7.  Any
ideas?  Thank you very much.  Geoff

--
Geoffrey Smith
Visiting Assistant Professor
Department of Finance
WP Carey School of Business
Arizona State University

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.