In our office we have a large (over 5 trillion rows) monthly data set stored in Oracle. IT guys decided to store date each month including the last day of the month in a format YYYYMMDD in a variable called: PER_NCOD which is indexed.
We used ODBC feature in Stata for data extraction but looping over dates was a problem, because last day of month follows exact rules for every month but variable for February. The most compact solution found is copied below, but better alternatives are welcome.
forvalues y = 2010/2015 {
forvalues m = 1/12 {
drop _all
local last_day = year(mdy(`m',1,`y')-1)*10000+month(mdy(`m',1,`y')-1)*100+day(mdy(`m',1,`y')-1)
odbc load, exec("SELECT * FROM OUR_DATABASE WHERE PER_NCOD=`last_day'") dsn("ABC") user(XYZ) password(123)
save OUR_`last_day'
}
}
We used ODBC feature in Stata for data extraction but looping over dates was a problem, because last day of month follows exact rules for every month but variable for February. The most compact solution found is copied below, but better alternatives are welcome.
forvalues y = 2010/2015 {
forvalues m = 1/12 {
drop _all
local last_day = year(mdy(`m',1,`y')-1)*10000+month(mdy(`m',1,`y')-1)*100+day(mdy(`m',1,`y')-1)
odbc load, exec("SELECT * FROM OUR_DATABASE WHERE PER_NCOD=`last_day'") dsn("ABC") user(XYZ) password(123)
save OUR_`last_day'
}
}
Comment