Statalist


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

Re: st: Forvalues, syntax error


From   "Neil Shephard" <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Forvalues, syntax error
Date   Thu, 5 Jul 2007 15:34:35 +0100

On 7/5/07, Gauri Khanna <gwkhanna@hotmail.com> wrote:
Dear Neil,

Thank you for your prompt suggestion.  I tried your suggestion and I seem to
get an error at the beginning. I have only copied a couple of lines from the
start to the point where the problem is identified.

Do you have any insight as to why the problem occurs? Thank you so much for
your help.

set more off
set matsize 5000
set trace on
set tracedepth 2

use `allsvys1', clear
egen i=group(un_region2 sex_code) if excind!=1 & sex_code!=3 &
total_age_group!=1 & agegrp==0
summarize i
local max1=r(max)
gen error1=.
gen error2=.
save `allsvys', replace


forvalues svy = 1/`max1' {
THIS IS THE ERROR I GET
- forvalues svy = 1/`max1' {
= forvalues svy = 1/. {
invalid syntax
r(198);
And there is your answer, for whatever reason the r(max) is picking up
"missing" (represnted by '.' in Stata) as the maximum value of i when
you summarize it.  Thus when you try to run a loop over 1 to the
maximum value of your variable i it actually tries to do it over
values 1 through to . which is obviously invalid Syntax

This is unusual as in Stata 9/SE for Linux I get..

<---------------------------->
. about

Stata/SE 9.2 for Unix
Born 12 Jan 2007
Copyright (C) 1985-2006

. sysuse auto, clear
(1978 Automobile Data)

. nmissing rep78

rep78               5

. sum rep78

   Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
      rep78 |        69    3.405797    .9899323          1          5

. return list

scalars:
                r(N) =  69
            r(sum_w) =  69
             r(mean) =  3.405797101449275
              r(Var) =  .9799658994032396
               r(sd) =  .9899322701090412
              r(min) =  1
              r(max) =  5
              r(sum) =  235

. local max = r(max)

. di `max'
5

<---------------------------->

What version of Stata are you using?  Can you run the above on the
auto data in your version?

Can anyone else replicate the behaviour that Gauri is seeing in the
same version with the ?

Neil
--
"In mathematics you don't understand things. You just get used to
them."  - Johann von Neumann

Email - nshephard@gmail.com / n.shephard@sheffield.ac.uk
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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