Statalist The Stata Listserver


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

st: RE: Variable names incompatable with aflogit?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Variable names incompatable with aflogit?
Date   Fri, 11 Aug 2006 20:03:23 +0100

Please do not send HTML to the list! 
Please do not send HTML to the list! 

The problem is not, I think, one of 
incompatibility. 

My surmise is that -aflogit- is broken by 
some recent tightening-up in Stata. 

The problem is with references to 

$`1' 

where Stata is expected by the programmer 
to take the local macro name first and then 
evaluate the global name that results. If that 
is what you want, you are expected to spell that 
out explicitly. 

Presumably this worked at one point, but 
(again I surmise) StataCorp perhaps tightened 
up on what was seen as a bug or a misfeature. 

A quick experiment indicates that changes 
to the code so that these lines read as below 
produces output. 

212     replace `1' = ${`1'} - `1'
241     gen `zmx' = ${`1'} - `1'
272     replace `1' = ${`1'} if `1' != .
281     replace `1' = ${`1'} if `1' != .        /* reset exposure to reference level */

That is, assignments referring to 

$`1' 

should be to 

${`1'} 

instead. 






Nick
[email protected] 

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of rps
Sent: 11 August 2006 19:10
To: [email protected]
Subject: st: Variable names incompatable with aflogit?


I have encountered the following problem when using the aflogit (sbe21.pkg) user-supplied module for calculating population attributable fraction (AF) following a logistic regression (the data set is tuyns.dta, which is distributed with the package): 

The following logistic regression command is issued:

xi: logit case i.alcohol [fw=n]

which produces:

i.alcohol         _Ialcohol_0-3       (naturally coded; _Ialcohol_0 omitted)

Iteration 0:   log likelihood = -494.74421
Iteration 1:   log likelihood = -428.70187
Iteration 2:   log likelihood = -421.84193
Iteration 3:   log likelihood = -421.49571
Iteration 4:   log likelihood = -421.49545

Logistic regression                               Number of obs   =        975
                                                  LR chi2(3)      =     146.50
                                                  Prob > chi2     =     0.0000
Log likelihood = -421.49545                       Pseudo R2       =     0.1481

------------------------------------------------------------------------------
        case |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 _Ialcohol_1 |    1.27124    .232332     5.47   0.000     .8158777    1.726602
 _Ialcohol_2 |   2.054459   .2611044     7.87   0.000     1.542704    2.566214
 _Ialcohol_3 |   3.304162   .3236511    10.21   0.000     2.669817    3.938506
       _cons |  -2.588542   .1925445   -13.44   0.000    -2.965922   -2.211161
------------------------------------------------------------------------------

Then the aflogit command is given:

aflogit _Ialcohol* [fw=n], cc

which produces the following error:

Population attributable fraction from logistic regression
Case-control data (n=975)

Using weights [fweight = n]

Term      Ref.     A.F.        s.e.      [95% Conf. Int.]*
----------------------------------------------------------
l_1 not found
r(111);

Referring to the model terms explicitly does not help, as in

aflogit _Ialcohol_1 _Ialcohol_2 _Ialcohol_3 [fw=n], cc

However, renaming _Ialcohol_1 _Ialcohol_2 _Ialcohol_3 as alcohol1 alcohol2 alcohol3, respectively, allows the aflogit module to execute:

logit case alcohol1 alcohol2 alcohol3 [fw=n]
aflogit alcohol1 alcohol2 alcohol3 [fw=n], cc

producing

[logistic regression outout omitted]
Population attributable fraction from logistic regression
Case-control data (n=975)

Using weights [fweight = n]

Term      Ref.     A.F.        s.e.      [95% Conf. Int.]*
----------------------------------------------------------
alcohol1   0      0.2698      0.0451      0.1759   0.3530
alcohol2   0      0.2223      0.0340      0.1526   0.2863
alcohol3   0      0.2167      0.0287      0.1584   0.2710
----------------------------------------------------------
TOTAL             0.7089      0.0508      0.5903   0.7931

* CI calculated on log(1-AF) scale

Any insight anyone can give as to why aflogit doesn't accept the original indicator variable names will be appreciated. For the present example, renaming the variables is a reasonable solution, but it becomes tedious is there are several factors in the model each with multiple indicator variables.

Thanks,

Richard Steiner
The University of Akron 

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