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

st: Extended macro problem


From   Fred Wolfe <[email protected]>
To   [email protected]
Subject   st: Extended macro problem
Date   Mon, 31 May 2004 22:17:35 -0500

I hope a macro guru might be able to help me with this problem.

Either I have made a mistake or there is a Stata bug.

I am developing a program to format the output from Roger Newson's -parmby-

Here is a snippet of code.

program define showparmest
version 8.2
syntax using/ [, Clearfile Sort ciform(string)]
preserve
qui compress
qui {

// identify the type of command
local command `e(cmd)'

// identify categorical variables used with "i." in an xi
local cmdline `r(command)'
foreach word of local cmdline {
if substr("`word'",1,2) == "i." {
local tname = substr("`word'",3,.)
local catlist `catlist' `tname' // macro catlist comtains i.cat vars
} // with i. stripped off
}

// get levels and omitted category for catvars
foreach catvar of local catlist {
levels `catvar', local(`catvar'lev) // lev in VARNAMElev
local `catvar'omit : char `catvar'[omit] // omit in VARNAMEomit
if "``catvar'omit'" == "" {
local `catvar'omit : word 1 of ``catvar'lev' // low cat if no char[omit]
}


foreach num of local `catvar'lev { // get value labels
local `catvar'lab`num': label `catvar' `num'
noi di "``catvar'lab`num''"
}


}
noi des sex edcat
noi lab list sex edcode2
noi tabl edcat

The key section to pay attention to is the section beginning // get value labels.
This section uses the extended macro function to assign value labels to macros.

In the //get value labels section, in the foreach cycle, -sex- is processed first then -edcat- . Both variables have value labels assigned but Stata only sees the labels for -sex-, not for -edcat-

Here is the output:

This is the parmby output to show you what I am doing. This is a nonsense regression for test purposes.

. parmby "xi:logistic married haq pain i.sex fatigue i.edcat age edlevel ", label eform format(estimate min95 max95 %8.2f p %8.1e) saving(killme,replace)
Command: xi:logistic married haq pain i.sex fatigue i.edcat age edlevel
i.sex _Isex_0-1 (naturally coded; _Isex_0 omitted)
i.edcat _Iedcat_0-4 (naturally coded; _Iedcat_2 omitted)

Logistic regression Number of obs = 7415
LR chi2(10) = 369.84
Prob > chi2 = 0.0000
Log likelihood = -4290.4222 Pseudo R2 = 0.0413

------------------------------------------------------------------------------
married | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
haq_disabi~y | .8444004 .0413379 -3.45 0.001 .7671453 .9294355
pain_scale | .9873622 .0132877 -0.95 0.345 .9616593 1.013752
_Isex_1 | 2.88479 .2257692 13.54 0.000 2.474557 3.363031
fatigue_sc~e | 1.003774 .0121381 0.31 0.755 .9802633 1.027848
_Iedcat_0 | .4256095 .1216269 -2.99 0.003 .2430874 .7451783
_Iedcat_1 | .6159096 .0804384 -3.71 0.000 .4768142 .7955816
_Iedcat_3 | 1.073439 .1213579 0.63 0.531 .8600911 1.339708
_Iedcat_4 | 1.294813 .301287 1.11 0.267 .8206213 2.043013
age | .980985 .002152 -8.75 0.000 .9767761 .985212
edlevel | .9171411 .0447198 -1.77 0.076 .8335498 1.009115
------------------------------------------------------------------------------
file killme.dta saved

Here is the output from my program snippet.

. showparmest using killme, s

Female
Male
0
1
2
3
4

Notice that the value labels are shown for sex (Female Male) but not for -edcat (shown as 0 1 2 3 4 ).

storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
sex byte %8.0g sex Patient's gender
edcat byte %9.0g edcode2 Education category
sex:
0 Female
1 Male
edcode2:
0 0-8
1 8-11
2 12
3 13-15
4 16 or >

edcat (Education category) code | Freq Percent
-------------------------------------+--------------------
0-8 0 | 255 2.81
8-11 1 | 748 8.25
12 2 | 3468 38.25
13-15 3 | 2270 25.04
16 or > 4 | 2325 25.65
-------------------------------------+--------------------
<missing value> . | 139
-------------------------------------+--------------------
Total | 9205 100.00

Notice that the value labels are shown in -describe-, -label list- and -tabl.
Thus the labels are there but the program is not processing them.

I hope someone may have a suggestion as to my error. Or is this a Stata bug.

Thanks,

Fred



Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125 Fax (316) 263-0761
[email protected]


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