Statalist The Stata Listserver


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

st: RE: Simple syntax question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Simple syntax question
Date   Thu, 20 Jul 2006 16:52:17 +0100

This isn't simple at all. You are quite confused. 

First, the -int- here appear to arise from some confusion 
between -local-s and variables. All you are 
doing is repeatedly over-writing a single 
local, with the name "int", with quite different
contents. So all the occurrences of "int" should 
be deleted. There is no way to specify that a macro
should hold integers (and only integers). 

Then references to ``i'' and ``j'' are references to 
macros with names `i' and `j'. These won't 
make sense unless you have, upstream of this code, 
by applying -tokenize- or otherwise, created local 
macros with names 1, 2, 3, etc. This is not fatal, 
but references to macros that do not exist will 
be interpreted as empty strings. 

What is more likely, at first glance, is that 
wherever you have 

``i'' 

you mean `i', and similarly with ``j''. 

A quite different comment is that you appear
to putting the same values into several different
macros. It isn't clear why you want to do that, 
or why you want to use macros at all, rather 
than use the constants 10 ... 100 directly. 

I don't understand your problem, but it doesn't
sound exotic. It's not clear that you need 
to write your own program. 

Nick 
n.j.cox@durham.ac.uk 

Serguei Kaniovski
 
> Hi all, I have something like this
> 
> *INITIALIZE SUMS;
> 
> forval i=1/5 {;
> 	local I=`i'+1;
> 	forval j=`I'/5 {;
> 		local int sum11_``i''_``j''=10;
> 		local int sum10_``i''_``j''=20;
> 		local int sum01_``i''_``j''=30;
> 		local int sum00_``i''_``j''=40;
> 		local int sumT_``i''_``j''=100;
> 	};
> };
> 
> *COMPUTE RELATIVE FREQUENCIES;
> forval i=1/100 {;
> 	local I=`i'+1;
> 	forval j=`I'/5 {;
> 		gen frq11_``i''_``j''=sum11_`i'_`j'/sumT_`i'_`j';
> 		gen frq10_``i''_``j''=sum10_`i'_`j'/sumT_`i'_`j';
> 		gen frq01_``i''_``j''=sum01_`i'_`j'/sumT_`i'_`j';
> 		gen frq00_``i''_``j''=sum00_`i'_`j'/sumT_`i'_`j';
> 	};
> };
> 
> I would like to generate the relative frequencies of the four 
> different 
> outcomes (sum-variables) and the total sum (sumT). All of these are 
> locals whilst frequencies should be data sheet variables, 
> hence the gen. 
> The problem is the syntax in the gen-argument. I can't get 
> the quotation marks correctly.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index