Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: AW: AW: confirm


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: AW: confirm
Date   Wed, 18 Aug 2010 13:15:17 +0200

<> 

Like so:


*************
clear*

//generate files
forv i =1/9{
	drop _all
	gen var1=1
	save 2006010`i', replace
}

//make "10" a missing file
forv i =11/20{
	drop _all
	gen var1=1
	save 200601`i', replace
}


//check for presence of files
local YEAR  2006
local MONTH 01 02 
local DAY 01 02 03 04 05 06 07 /* 
*/  08 09 10 11 12 13 14 15 16  /* 
*/ 17 18 19 20 


foreach Y of local YEAR  {
foreach M of local MONTH {
foreach D of local DAY {

scalar day = mdy(`M',`D',`Y')
scalar satsun = dow(day)

if !inlist(satsun,.,0,6){
	capt conf file "`Y'`M'`D'.dta"
	if _rc{
		di as err "This file `Y'`M'`D'.dta is not there, I am afraid"
	}
	else{
		di in red "This file `Y'`M'`D'.dta is already there!"
	}
}

}
}
}
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Mittwoch, 18. August 2010 12:53
An: [email protected]
Betreff: st: AW: confirm


<> 

Just -capture- the -confirm- statement, and condition on the return code

*************
sysuse auto, clear
foreach var in newvariable price weight{
capt conf new variab `var'
di in red _rc
}
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Dimitri Szerman
Gesendet: Mittwoch, 18. August 2010 12:25
An: statalist
Betreff: st: confirm

Hello,

Here's what I'm trying to do. I have a directory with many files, one for
each weekday of the year. Some files are missing, and I want to find out
which files are missing. The filenames make it easier to use a loop and
confirm, and I came up with this:

local YEAR  2006
local MONTH 01 02 03 04 05 06 07 08 09 10 11 12
local DAY 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31

 foreach Y of local YEAR  {
 foreach M of local MONTH {
 foreach D of local DAY {

 scalar day = mdy(`M',`D',`Y')
 scalar satsun = dow(day)

if satsun!=0 & satsun!=6 & satsun!=. {
confirm file "`Y'`M'`D'.csv"
}

 }
 }
 }

Now, my problem is, this code will stop on the first missing file. What I'd
like is to have is Stata printing a list of missing files. Any ideas would
be much appreciated.

Many thanks,
Dimitri
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index