Hello,


I'm trying to construct a foreach loop where I am using a few words as the phrase to loop over to specify the regression variables, graph title and saved graph name. However, there is an invalid syntax error, which I think has to do with STATA either not recognizing the "" or the spaces. How do I specify that correctly?


Here is an example below that would result in that error:

Code:
foreach `x' in "y x" "y z" {

reg `x' i.year

twoway (connected `x') ///
, title(`x'- model, size(medsmall))

graph export C:\Documents\model-diagnostic\`x'- model.pdf, replace

}
Here is what I want it to do in the first loop:

Code:
reg y x i.year

twoway (connected y x) ///
, title(y x- model, size(medsmall))

graph export C:\Documents\model-diagnostic\y x- model.pdf, replace
secondarily, would STATA also have trouble with there being a space in the graph export file name?

Thank you in advance!