Announcement

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

  • Summarise by equal and increasing groups

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 make int(price mpg rep78) float headroom int(trunk weight length turn displacement) float gear_ratio byte foreign
    "AMC Concord"        4099 22 3 2.5 11 2930 186 40 121 3.58 0
    "AMC Pacer"          4749 17 3   3 11 3350 173 40 258 2.53 0
    "AMC Spirit"         3799 22 .   3 12 2640 168 35 121 3.08 0
    "Buick Century"      4816 20 3 4.5 16 3250 196 40 196 2.93 0
    "Buick Electra"      7827 15 4   4 20 4080 222 43 350 2.41 0
    "Buick LeSabre"      5788 18 3   4 21 3670 218 43 231 2.73 0
    "Buick Opel"         4453 26 .   3 10 2230 170 34 304 2.87 0
    "Buick Regal"        5189 20 3   2 16 3280 200 42 196 2.93 0
    "Buick Riviera"     10372 16 3 3.5 17 3880 207 43 231 2.93 0
    "Buick Skylark"      4082 19 3 3.5 13 3400 200 42 231 3.08 0
    "Cad. Deville"      11385 14 3   4 20 4330 221 44 425 2.28 0
    "Cad. Eldorado"     14500 14 2 3.5 16 3900 204 43 350 2.19 0
    "Cad. Seville"      15906 21 3   3 13 4290 204 45 350 2.24 0
    "Chev. Chevette"     3299 29 3 2.5  9 2110 163 34 231 2.93 0
    "Chev. Impala"       5705 16 4   4 20 3690 212 43 250 2.56 0
    "Chev. Malibu"       4504 22 3 3.5 17 3180 193 31 200 2.73 0
    "Chev. Monte Carlo"  5104 22 2   2 16 3220 200 41 200 2.73 0
    "Chev. Monza"        3667 24 2   2  7 2750 179 40 151 2.73 0
    "Chev. Nova"         3955 19 3 3.5 13 3430 197 43 250 2.56 0
    "Dodge Colt"         3984 30 5   2  8 2120 163 35  98 3.54 0
    end
    label values foreign origin
    label def origin 0 "Domestic", modify
    With the data above, I would like to summarise price and generate its sd. Forexample:
    I summarise price in 1/2 and save the sd at 2,
    then I summarise price in 2/3 and save sd at 3
    hen I summarise price in 3/4 and save sd at 4
    .......all the way to the end
    Last edited by Cyrus Muriithi; 19 Aug 2022, 23:29.

  • #2
    Try the following code: gen id = _n

    rangestat (count) price (mean)price (sd) price , interval( id -1 0)

    Comment


    • #3
      Originally posted by Itesh New View Post
      Try the following code: gen id = _n

      rangestat (count) price (mean)price (sd) price , interval( id -1 0)
      Thank you Itesh,
      This is what has finally worked:

      gen id = _n

      rangestat (count) Price (mean) Price (sd) Price , interval( id -11 0)

      Comment

      Working...
      X