[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: reshape command with dates

From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: reshape command with dates
Date   Thu, 30 Oct 2008 07:45:03 -0400

< >
Hugh said

I have a string variable (Id) with about 500 observations. I want to
create a date sequence for each Id ranging from July 1, 2002 to Dec
31, 2006 as below:-

I don't think you want to create 1,645 variables. Try

set obs 1645
// ssc inst tsmktim
tsmktim dd, start(1jul2002)
g long fmd = year(dd)*10000 + month(dd)*100 + day(dd)
format fmd %9.0f
g en = _n
l in 1/10
l in -10/l

Save this as a Stata dataset, -expand- your existing file by 1645, and create a sequence number called -en- in the expanded file that goes 1,...,1645, 1,...,1645, etc. with -egen-. Then you can -merge- the expanded file with the date sequence file, and you will have a file with IDs and dates in the YYYYMMDD format.

Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

*   For searches and help try:

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