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

st: Re: Extended macro problem


From   Kaleb Michaud <[email protected]>
To   [email protected]
Subject   st: Re: Extended macro problem
Date   Tue, 01 Jun 2004 00:17:58 -0700

Fred,

You're going to groan yourself when you see the error. Everything's fine, but you're assuming the name of the label values is the same name as the categorical variable. In the case of sex, it works out, but edcat's label is edcode2 and what the code basically does is:

local edcatlab0 : label edcat 0

when what you really want is:

local edcatlab0 : label edcode2 0

Just add a line that grabs the correct label value name before this and you should be good.

Kaleb...


At 08:17 PM 5/31/2004, you wrote:

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)

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
I hope someone may have a suggestion as to my error. Or is this a Stata bug.

Thanks,

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