Hello Statalist.
I have trouble understanding exactly how a specific loop function works. I am doing a loop that can have two outcomes; either the loop is run and a pdf is created in one way or the loop runs but creates a different pdf. My problem is, that the loop seemingly ignores my if/else statement and always jumps to my last statement even if countcheck is smaller than .8 but this is, of course, because I am missing something important. This is what I've been doing:
For a more generalized version, consider this:
Here it works. What am I doing wrong?
I have trouble understanding exactly how a specific loop function works. I am doing a loop that can have two outcomes; either the loop is run and a pdf is created in one way or the loop runs but creates a different pdf. My problem is, that the loop seemingly ignores my if/else statement and always jumps to my last statement even if countcheck is smaller than .8 but this is, of course, because I am missing something important. This is what I've been doing:
Code:
local dta : dir . files "*.dta" local dta : subinstr local dta ".dta" "", all foreach x of local dta { use `x'.dta, clear capture putpdf clear putpdf begin putpdf paragraph, halign(left) if countcheck<.8 { putpdf text ("Sample is too small") putpdf save `x'.pdf, replace } else { putpdf text ("A lot of words I don't want to write here") putpdf save `x'.pdf, replace } }
For a more generalized version, consider this:
Code:
sysuse auto, clear levelsof rep78, local(rep) foreach x of local rep { sum price if rep78==`x' if `r(mean)'<5000 { di "fish" } else { di "cow" } }
Comment