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

Re: st: RE: Generating grouped variable list of xi'd variables via column names

From   "K Jensen" <>
Subject   Re: st: RE: Generating grouped variable list of xi'd variables via column names
Date   Fri, 13 Jul 2007 13:06:48 +0100

Thanks, Maarten - as ever, this is really helpful.

I'm afraid that macro programming puts my head in a spin... I was
wondering how easy it would be to convert the results in model_I
 di "`model_I'"
 _Idrug_2 _Idrug_3 _Irandcat_2 _Irandcat_3
to the form _Idrug* _Irandcat*

Sorry to be a pest again,

P.S. I realized the problem with the way I had created randcat the
second after I had clicked on send!

On 13/07/07, Maarten Buis <> wrote:
--- K Jensen wrote:
I would like to generate lists of groups of variables that have been
generated via xi from the column names of the vector e(b) after
regression commands.
It's probably easier to explain with an example...

  sysuse cancer
  stset studytime, fail(died)
  gen randcat=1
  replace randcat=2 if uniform()>1/3
  replace randcat=3 if uniform()>2/3
  xi:stcox i.drug age i.randcat

  . matrix list e(b)

         _Idrug_2     _Idrug_3          age  _Irandcat_2  _Irandcat_3
  y1   -1.7300519   -3.2313217    .12791436   -.93457115   -.77850524

I would like to take the column names from e(b) to generate a varlist
of the xi-generated variable groups, something like:
_Idrug* _Irand*

With the -unab- command you can get a list of all variable names
starting with _I, with the -indeplist- command (downloadable from ssc)
you can get a list of all independent variables in your model, and
with the list extended macro function you combine these two list to
create a list of all _I variables that are in your model. See the
example below:

*-------------- begin example -----------
sysuse cancer, clear
stset studytime, fail(died)
gen randcat= ceil(3*uniform())
xi:stcox i.drug age i.randcat

indeplist, local
di "`X'"
unab all_I : _I*
local model_I : list all_I & X
di "`model_I'"
*-------------- end example -------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

Ps. Notice that I created the variable randcat differently. You
created it by calling the function uniform() twice. That way
-uniform()>1/3- and -uniform()>2/3- can both be true since they
refer to different random numbers. More on this in Stata Tip 48
which will appear in the next Stata Journal. A pre-publication
draft is downloadable from my website.

Maarten L. Buis
*   For searches and help try:

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