Statalist


[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" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Generating grouped variable list of xi'd variables via column names
Date   Fri, 13 Jul 2007 14:16:09 +0100

Thanks, Maarten - that works perfectly.

You're my hero!
Karin

On 13/07/07, Maarten Buis <[email protected]> wrote:
--- K Jensen wrote:
> 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*

A slightly messy solution is shown below. As you are probably
using this repeatedly in your do-file it might be useful to
create a program at the beginning of your do-file that does
this (call it -ab_i-), so in the remainder of your do-file you
can refer to -ab_I- whenever you want to do this. This way
your do-file will look cleaner and easier to understand (and
debug).

*------------- begin example -------------
capture program drop ab_I
program define ab_I
        *!version 1.0.0 MLB 13 July 2007
        /*get list of all _I vars*/
        qui indeplist, local
        unab all_I : _I*
        local model_I : list all_I & X

        /*abbreviate _I vars*/
        local min_I : subinstr local model_I "_I" "", all
        foreach stub of local min_I {
                gettoken temp : stub, parse("_")
                local ab "`ab' _I`temp'*"
        }
        local ab : list uniq ab
        c_local ab "`ab'"
end

sysuse cancer, clear
stset studytime, fail(died)
gen randcat= ceil(3*uniform())
xi:stcox i.drug age i.randcat
ab_I
di "`ab'"
*--------------- end example -------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------




*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index