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

RE: st: RE: programming question

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: programming question
Date   Fri, 5 Jul 2002 14:09:48 +0100

Miss Paul

> I have figured out what was going wrong. However, I have another 
> question. I
> keep getting the same output regardless of what variable is chosen. I
> thought each new value of "``k''"  also corresponded to each subsequent
> variable in the variable list. Am I mistaken about that?

In your code fragment 

local k = 2
while "``k''" ~= "" {
	local kless1 = `k' - 1
	tempvar e2var`kless1'q
	ge `e2var`kless1'q' = `e2qq' * ``k'' `if'
	if "`heteroscedasticity'" ~= "" { 
		local namevar: word 1 of `heteroscedasticity'
	tempvar hetvar
	foreach var of varlist `varlist' {
		if "`var'" == "``k''" {
			ge `hetvar' = `e2var`kless1'q'
	local k = `k' + 1

whatever is in "``k''" (which will in turn be "`2'", "`3'", 
etc. as you go round in the loop) will depend on 

1. the previous -parse-, or 

2. the previous -tokenize-, or 

3. the previous explicit assignment to local macros with names 
2, 3, etc., or 

4. Stata's parsing of your arguments as you entered the program, 

whichever happened most recently. (Like cushions, macros bear the imprint 
of whatever last sat on them.) Whichever it was, it happened before
any of the code you present, so far as I can see. 

So the best advice I can give is to recommend that you insert 

noi mac li 

to get Stata to say what is in what macro. You may need to pepper 
your program with a few such statements to work out where things
are going wrong. 

[email protected] 
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index