Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Looping within a subset under a certain condition


From   "Gerard Solbrig" <[email protected]>
To   <[email protected]>
Subject   RE: st: Looping within a subset under a certain condition
Date   Sun, 30 Sep 2012 22:15:08 +0200

Here's what Stata says:

- forvalues x = 1/`r(max)' {
= forvalues x = 1/18554 {
- summarize obs if firm_numid == `x' & rep == 0, meanonly
= summarize obs if firm_numid == 1 & rep == 0, meanonly
- local z1 = r(min)
- local z2 = r(max)
- summarize obs if firm_numid == `x' & rep == 1, meanonly
= summarize obs if firm_numid == 1 & rep == 1, meanonly
- local o1 = r(min)
- local o2 = r(max)
- forvalues i = `z1'/`z2' {
= forvalues i = 1/106 {
- local isin = 1
- forvalues o = `o1'/`o2' {
= forvalues o = ./. {
invalid syntax
  if inrange(trandate[`i'], wind_start[`o'], wind_end[`o']) {
  local isin = 0
  }
  if `isin' == 1 replace rep_ins = 1 in `i'
  }
  }
r(198);



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Sonntag, 30. September 2012 21:53
To: [email protected]
Subject: Re: st: Looping within a subset under a certain condition

This code refers to -date- and -trandate- at different places.

gen long obs = _n

was recommended earlier.

Type

set trace on
set tracedepth 1

before running the code and see which line produces the error.

On Sun, Sep 30, 2012 at 7:28 PM, Gerard Solbrig
<[email protected]> wrote:
> I'm sorry, but I've been trying for hours now: Stata yields me 
> "invalid syntax r(198);" every time I try to run this code:
>
> sort cusip6 rep date
> gen obs = _n
> gen rep_ins = 0
> egen firm_numid = group(cusip6)
> summarize firm_numid, meanonly
> forvalues x = 1/`r(max)' {
>         su obs if firm_numid == `x' & rep == 0, meanonly
>         local z1 = r(min)
>         local z2 = r(max)
>         su obs if firm_numid == `x' & rep == 1, meanonly
>         local o1 = r(min)
>         local o2 = r(max)
>         forvalues i = `z1'/`z2' {
>                 local isin = 1
>                 forvalues o = `o1'/`o2' {
>                         if inrange(trandate[`i'], wind_start[`o'],
> wind_end[`o']) {
>                         local isin = 0
>                         }
>                 if `isin' == 1 replace rep_ins = 1 in `i'
>                 }
>         }
> }
>
> Despite countless tries and modifications, I cannot find the mistake 
> in the syntax. I simply don't know what is supposed to be wrong here.
> I know this code should be working the way I need it...
>
> Many thanks in advance.
> Gerard
>
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index