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

st: RE: if "macro" == value {


From   "James Harris" <[email protected]>
To   <[email protected]>
Subject   st: RE: if "macro" == value {
Date   Tue, 3 Feb 2004 17:44:58 +1100

>> i am running that looks like:
>> 
>> foreach S in fa sp ts {
>> 	if [the macro S] ~="ts" {
>> 		-- extra commands --
>> 	}
>> }
>> 
>> that is, i'm performing a set of commands once for the "fa" 
>> string, once
>> for "sp", and once for "ts".  my problem: i can't figure 
>> out how to refer
>> to the macro `S' and have stata realize that i'm referring 
>> to the macro
>> `S' and not a variable named S or "fa", etc...
>> 
>> is there a way to write this so that i can test whether the 
>> macro S is
>> equal to a given string fa, sp, or ts ?
>> 

>foreach S in fa sp ts {
>	if "`S'" ~= "ts" {
> 		-- extra commands --
> 	}
>}
>
>Also see [P] foreach; Stata Journal 2(2), 202-222 (2002) 
>
>Nick 
>[email protected] 



I have a question related to the one answered above. In the following code, all works well up until line 8 (the poisson command), which returns 
exposure():  pop25m:  string variable not allowed

1	foreach ICD in i21 {
2		foreach age in 25 35 45 {
3			foreach sex in m f {
4				local deaths = "`ICD'_`age'`sex'" 
5				local population = "pop`age'`sex'"
6				macro list
7				list year `ICD'_`age'`sex' pop`age'`sex' `deaths' `population'
8				poisson `deaths' year, exposure (`population')
9			}
10		}
11	}

In other words, it appears that the list command interprets the local macro `population' as a varname, but the exposure() part of the poisson command does not. 

Any comments gratefully received. 

with thanks,

James.


 ==========================================
 
James Harris
 
National Centre for Epidemiology and Population Health
The Australian National University
CANBERRA ACT 0200
Australia

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