Stata returns an error when I integrate an if-command within a loop. I hope the answer to this question is not too obvious - as I don't see the mistake (I fear it is a typo...) - but it is my first time I try to produce some more generic do-files for the same task.
I do have the following code:
With set trace on I get:
- if "`l'" == "pro" | "`l'" == "qual" | "`l'" == "koop" | "`l'" == "vera" {
= if "pub" == "pro" | "pub" == "qual" | "pub" == "koop" | "pub" == "vera" {
if "`l'" == "pro" | "`l'" == "koop" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_ende
}
else "`l'" == "qual" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_pruefdat
}
- else "`l'" == "vera" {
= else "pub" == "vera" {
"pub is not a valid command name
local beginn ``l'_db'_start
local ende ``l'_db'_ende
}
r(199);
end of do-file
r(199);
Your help is very much appreciated.
I do have the following code:
Code:
foreach l in pro pub qual koop preis vera {
*** Some more if-commands that work well
*** The problematic part when the loop is at pub
if "`l'" == "pro" | "`l'" == "qual" | "`l'" == "koop" | "`l'" == "vera" {
if "`l'" == "pro" | "`l'" == "koop" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_ende
}
else "`l'" == "qual" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_pruefdat
}
else "`l'" == "vera" {
local beginn ``l'_db'_start
local ende ``l'_db'_ende
}
***Some more code
}
- if "`l'" == "pro" | "`l'" == "qual" | "`l'" == "koop" | "`l'" == "vera" {
= if "pub" == "pro" | "pub" == "qual" | "pub" == "koop" | "pub" == "vera" {
if "`l'" == "pro" | "`l'" == "koop" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_ende
}
else "`l'" == "qual" {
local beginn ``l'_db'_beginn
local ende ``l'_db'_pruefdat
}
- else "`l'" == "vera" {
= else "pub" == "vera" {
"pub is not a valid command name
local beginn ``l'_db'_start
local ende ``l'_db'_ende
}
r(199);
end of do-file
r(199);
Your help is very much appreciated.

Comment