Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Access datasets created by date


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Access datasets created by date
Date   Fri, 01 Apr 2005 12:07:52 -0500

You may need to change this code to suit your operating system. I use WinXP, so it may work for Win2000 or may not. Also, if you have very long file names you may want to change the infix command to read more than 80 characters. The filespec may include directory info too, whatever works in your OS.

program define dayfiles, rclass
version 8.2
syntax [, Filespec(str) IFDate(str)]
preserve
drop _all
if "`filespec'"=="" local filespec "*.*"
!dir `filespec' > mydir.txt
quietly{
infix str x 1-80 using mydir.txt
split x
gen int date=date(x1,"mdy",2040)
drop if date==.
rename x5 filename
keep date filename
if "`ifdate'"!="" keep if date==`ifdate'
forval i =1/`=_N-1' {
local f `"`f'`"`=filename[`i']'"' "'
}
if _N>0 local f `"`f'`"`=filename[_N]'"'"'
}
return local files `"`f'"'
end

This ado uses the shell command to write a text file with the directory info, then reads it into Stata, parses the text lines, and puts a listing of filenames in r(files) that match the date you specify. Example:

dayfiles, f(*.txt) ifdate(mdy(3,30,2005))

should produce a local macro r(files) that contains the list of text files saved on 3/30/2005. You could then

foreach file in `r(files)' {
insheet var1 var2 var3.... using `file'
....
}

Michael Blasnik
[email protected]

----- Original Message ----- From: "MITRA PINAKI (MAR1PXM)" <[email protected]>
To: <[email protected]>
Sent: Friday, April 01, 2005 10:04 AM
Subject: st: Access datasets created by date



Hello All,

   I have a list of text files in a folder which becomes available
daily. I would like to access these daily files by date in my program.
Is it possible in stata to identify the datasets created by date? My
dataset are named like the following:

Name Date Modified
PARCEL.G1911V00 03/29/05
PARCEL.G1921V00 03/29/05
PARCEL.G1914V00 03/30/05
and so on.

In my program, I would only like to capture PARCEL.G1911V00 and
PARCEL.G1921V00 since they are created on the same date (03/29/05) and
ignore PARCEL.G1914V00 which I would like to capture on 03/30/05's run.

Thank you.

Sincerely,
Pinaki Mitra
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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