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

Re: st: Re: two questions about matrix operations


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Re: two questions about matrix operations
Date   Thu, 6 Jan 2005 15:30:02 +0100

Katsuhide Isa wrote:
> As to the 1st question, when I ran the following,
>
> >foreach var of varlist A-D{
> >	count if `var' == 0
> >	local sum = `sum' + r(N)
> > }
> >di `sum'
>
> following error messages are shown:
>
> Unknown function +r()
> r(133);

The problem is, that the local macro `sum' isn't defined in the first round of 
the loop. 

local sum 0
foreach var of varlist A-D {
	count if `var' == 0
	local sum = `sum' + r(N)
}
di `sum'

should work. This is nicer than your solution in that you save one command 
inside the loop. However with just four loops this will not make any 
difference. 

> But this time, after numbers of zeros for each variable and
> total sum of zeros are vertically shown, following error
> messages appear:
> # The same messages are shown after running the statements
> pertaining to the 2nd question.
>
> no; data in memory would be lost
> r(4);

This message does not stem from the snippet above.  If you load several files 
in a loop you should load them with -use filename, clear-. However it might 
be an idea to merge/append the files toghether before starting the analysis. 

many regards
uli

-- 
[email protected]
+49 (030) 25491-361


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