I am not clear why you are doing this in a loop. Any way,
so far as I can see the answer lies in compound double
quotes. That was one of your guesses, but I can't comment
on what you did wrong, because you don't show us any attempt
using those.
local pretty_names `" "Drug name 2" "Drug name 3" "Age (years)" "'
There are two rules at work here.
1. Stata matches " by looking for the next one. You can't nest
" " in Stata. This is Stata's defence against the ambiguity of
(e.g.) "a "b" c".
2. Stata matches `" by looking for a matching "'.
and a meta-rule:
0. Symmetric quotes (in which opening and closing symbols are
identical) can't be nested; asymmetric quotes can be nested.
Don't quote me on that.
Nick
[email protected]
Karin Jensen
Help! Yet again I am having problems with quotes. I am trying to
generate a list of strings, some of which contain spaces, in order to
provide more descriptive labels when I write the results of a
regression to a file.
For example:
sysuse cancer, clear
stset studytime, fail(died)
xi:stcox i.drug age
tempname B
matrix `B' = e(b)
tokenize "`: colfullnames `B''"
local pretty_names
forval j = 1/`= colsof(`B')' {
if "``j''"=="_Idrug_2" {
local pretty_names `pretty_names' DrugName2
}
else if "``j''"=="_Idrug_3" {
local pretty_names `pretty_names' DrugName3
}
else if "``j''"=="age" {
local pretty_names `pretty_names' Age(years)
}
else {
local pretty_names `pretty_names' ``j''
}
}
I would like the elements in the list pretty_names to actually be
"Drug name 2", "Drug name 3", "Age (years)".
Every attempt I make to create such a list (in practically every
combination of compound double and other quotes, tried out of despair)
results in either a syntax error or a list with too many elements,
where "Drug", "name", "2", etc are separate items.