Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: how to make xi dummies inherit labels


From   Roger Harbord <Roger.Harbord@bristol.ac.uk>
To   statalist@hsphsun2.harvard.edu, Nick Cox <n.j.cox@durham.ac.uk>
Subject   Re: st: RE: RE: how to make xi dummies inherit labels
Date   Wed, 02 Oct 2002 18:49:40 +0100

Ta very much Nick. I'm still a little surprised if no-one else has tried to add this to the capabilities of (one or more of) -xi-, -outreg- or
-reformat-. I've only just felt the need for it but then i've only just started analysing surveys with many categorical explanatory variables in Stata. I'm hardly the first person to do that though.

Roger.


--On 02 October 2002 17:50 +0100 Nick Cox <n.j.cox@durham.ac.uk> wrote:


Roger Harbord
>
> Is there a way to make the dummy variables created by -xi-
> inherit their
> variable labels from the value labels of the variable in
> question?  It
> seems to me this would greatly improve the readability of
> the output of
> either
> -outreg- or -reformat-  after a regression command used with
> -xi-.
>
> Maybe I could write something to do this myself, but I
> can't believe
> someone hasn't done it before (but if so i've failed to findit).
>
> Below is an illustration of what happens at present.  I'd
> like e.g. the
> variable label of _Iage10yr2_2 to be "25-34" (the value
> label for 2)
> instead of "Age10yr2==2".
>
> Hope that's clear..
> Thanks,
> Roger.
>
> . label list age10yr2
> age10yr2:
>            1 16-24
>            2 25-34
>            3 35-44
>            4 45-54
>            5 55-64
>            6 65-74
>
> . xi: logistic siweekT2 i.age10yr2
> i.age10yr2        _Iage10yr2_1-6      (naturally coded;
> _Iage10yr2_1
> omitted)
>
> Logit estimates                                   Number
of obs   =
> 2406
>                                                   LR
chi2(5)      =
> 1.02
>                                                   Prob >
chi2     =
> 0.9609
> Log likelihood = -283.87549                       Pseudo
R2       =
> 0.0018
>
> ------------------------------------------------------------
> ----------------
>     siweekT2 | Odds Ratio   Std. Err.      z    P>|z|
> [95% Conf.
> Interval]
> -------------+----------------------------------------------
> ---------------
> ---
> _Iage10yr2_2 |   1.241561   .7320912     0.37   0.714     .3908894
> 3.943504
> _Iage10yr2_3 |    1.35575   .7829916     0.53   0.598     .4371014
> 4.20511
> _Iage10yr2_4 |   1.550725   .8883524     0.77   0.444     .5045602
> 4.766025
> _Iage10yr2_5 |   1.461749   .8738824     0.64   0.525     .4528932
> 4.717909
> _Iage10yr2_6 |   1.632203   .9917213     0.81   0.420     .4961204
> 5.369842
> ------------------------------------------------------------
> ---------------
> ---
>
> . describe _I*
>
>               storage  display     value
> variable name   type   format      label      variable label
> ------------------------------------------------------------
> ---------------
> ----
> _Iage10yr2_2    byte   %8.0g                  age10yr2==2
> _Iage10yr2_3    byte   %8.0g                  age10yr2==3
> _Iage10yr2_4    byte   %8.0g                  age10yr2==4
> _Iage10yr2_5    byte   %8.0g                  age10yr2==5
> _Iage10yr2_6    byte   %8.0g                  age10yr2==6
>
> . reformat, eform
>
> LOGISTIC  formatted output
>
> Outcome variable: siweekT2 (Suicidal in week before T2), n=2406
> ------------------------------------------------------------
> ----------------
> Covariate            Odds Ratio  Std. Err.      P>|z|  (95%
> Conf. Interval)
> ------------------------------------------------------------
> ----------------
> Age10yr2==2
>   per unit                1.242      0.732      0.714
> (0.391 to 3.944)
> Age10yr2==3
>   per unit                1.356      0.783      0.598
> (0.437 to 4.205)
> Age10yr2==4
>   per unit                1.551      0.888      0.444
> (0.505 to 4.766)
> Age10yr2==5
>   per unit                1.462      0.874      0.525
> (0.453 to 4.718)
> Age10yr2==6
>   per unit                1.632      0.992      0.420
> (0.496 to 5.370)
> ------------------------------------------------------------
> ----------------
>
> . outreg using test.out
>
> . type test.out
>         Suicidal in week before T2
> age10yr2==2     1.242
>         (0.37)
> age10yr2==3     1.356
>         (0.53)
> age10yr2==4     1.551
>         (0.77)
> age10yr2==5     1.462
>         (0.64)
> age10yr2==6     1.632
>         (0.81)
> Observations    2406
> Absolute value of z statistics in parentheses
> * significant at 5%; ** significant at 1%

I don't know a way to do this except directly:

forval i = 2/6 {
	local label : label (age10yr2) `i'
	label var _I_age10yr2_`i' "`label'"
}

Once learned, you can modify according to
taste, e.g.

forval i = 2/6 {
	local label : label (age10yr2) `i'
	label var _I_age10yr2_`i' "age `label'"
}


Nick
n.j.cox@durham.ac.uk
Alternatively, this is a canned solution:

program def roger
	version 7
	syntax varlist, Inherit(varname)
	foreach v of local varlist {
		local where = index(reverse("`v'"),"_")
		local value = substr("`v'",-`where' + 1,.)
		local label : label (`inherit') `value'
		label var `v' `"`label'"'
	}
end

e.g

roger _Iage10yr2*, inherit(age10yr2)

Nick
n.j.cox@durham.ac.uk

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