Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: List with strings containing spaces


From   "K Jensen" <k.x.jensen@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: List with strings containing spaces
Date   Thu, 19 Jul 2007 14:38:36 +0100

Thanks very much, Nick - I see where I went wrong.

Just out of curiosity: how would you take the names of the variables
from the column names of e(B) - in an unspecified order - and generate
a list of selected descriptors *without* using a loop?

Thankyou
Karin

On 18/07/07, n j cox <n.j.cox@durham.ac.uk> wrote:
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
n.j.cox@durham.ac.uk

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.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index