[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: filling in weekend dates

From   Maarten buis <>
Subject   Re: st: filling in weekend dates
Date   Thu, 19 Jun 2008 15:48:52 +0100 (BST)

--- Mingfeng Lin <> wrote:
> Is there a way to create new rows and then fill in weekend dates
> automatically in Stata? For instance, I have a series of stock
> prices, and Jan01-Jan05 are Monday-Friday, and weekend dates are not
> available.
> What I want to do is to "insert rows", say Jan06 and Jan07, such that
> they take on the value of Jan05.  The only way I can think of is to
> create this series of dates in Excel, then import to Stata and merge
> it, and then use [_n-1] to replace the missing values.  But is there
> a more straightforward way? I have a bunch of these files with
> different date ranges and it's really inefficient.

*------------- begin example ----------------
tempfile a b
sysuse sp500, clear
sort date
save `a'

sum date, meanonly
local min = r(min)
local days = r(max) - r(min) + 1

drop _all
set obs `days'
gen date = _n + `min' - 1
sort date
save `b'

merge date using `a'
format date %td
*-------------- end example ---------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

Sent from Yahoo! Mail.
A Smarter Email
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index