Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop over values of a given variable: looping over some particular values

    Dear Stata users,

    I am trying to run a loop over values of a given variable, called "zaocode".
    My aim is to run the loop for certain values of this variable, but the values have no logical meaning or "ordering", in the sense that I need to loop over some given values: 31 32 34 36 45 and 72 (rather than values from a given interval, or in a given range with regular increments in value)

    I am trying to list the values over which to loop using the foreach loop but stata wont recognise the sintax.

    I am trying to run a loop version of the following individual command for one of the values of my variable only:

    _pctile price if zaocode==11, percentiles(99)
    scalar p99_11 = r(r1)

    Could anyone give me on how do run a loop on those commands with the specific values of zaocode mentioned above?

    many thanks
    Last edited by basile; 19 Feb 2015, 04:52.

  • #2
    no need to loop:

    Code:
    bys zaocode : egen pct99 = pctile(price), p(99)
    Also note the Stata FAQ. You are asked to use your real name on this list. This has a long tradition here. We consider that a sign of mutual respect, and we feel that it has lead to a friendly and professional atmosphere here, which we like to keep.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Many thanks,!

      Comment

      Working...
      X