Announcement

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

  • creating group and then calculating total obsevation for each group needed for bunch_count

    Hello,
    I want to create groups using sales data which ranges from 400000 to 1.31e+09, I want to build groups with 100000 intervals. I tried
    egen salesgroup=cut(sales) if sales>0 , at(400000(100000)3.00e+08)
    But I get the following error message:
    at() invalid -- invalid numlist has too many elements
    Which I think crosses stata limits of elements. Then I created separate groups for a different range of values, which worked.

    Question 1) Any other smarter way to deal with this?

    Question 2) I am using 20 countries data, I want to use loop for each datafile (my data file are separate for each country). I tried for two countries say A and B,

    foreach c in "A" "B" {
    use data_country_`c', clear
    sum sales, detail
    egen salesgroup_`c'=cut(sales) if sales>0 , at(`r(min)'(100000)`r(p99)')
    I am getting the following error: at() invalid -- invalid numlist

    Any suggestions? Thanks

    Shafiun
    University of Nebraska-Lincoln





  • #2
    Reading list:

    SJ-3-4 dm0002 . . . . . . . . Stata tip 2: Building with floors and ceilings
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q4/03 SJ 3(4):446--447 (no commands)
    tips for using floor() and ceil()

    http://www.stata-journal.com/sjpdf.h...iclenum=dm0002

    SJ-11-3 dm0058 . . . . . . . . Speaking Stata: Fun and fluency with functions
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q3/11 SJ 11(3):460--471 (no commands)
    a tour of easily missed or underestimated Stata functions

    http://www.stata-journal.com/sjpdf.h...iclenum=dm0058 pp.464-5

    Consider this:

    Code:
    * build sandbox for play
    clear
    set obs 100
    local min = log(400000)
    local max = log(3e8)
    range y `min' `max'
    replace y = exp(y)
    
    * technique
    gen y2 = 1e5 * floor(y/1e5)
    tab y2
    
    . tab y2
    
             y2 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
         300000 |          1        1.00        1.00
         400000 |          3        3.00        4.00
         500000 |          3        3.00        7.00
         600000 |          2        2.00        9.00
         700000 |          2        2.00       11.00
         800000 |          2        2.00       13.00
         900000 |          1        1.00       14.00
        1000000 |          2        2.00       16.00
        1100000 |          1        1.00       17.00
        1200000 |          1        1.00       18.00
        1300000 |          1        1.00       19.00
        1400000 |          1        1.00       20.00
        1500000 |          1        1.00       21.00
        1600000 |          1        1.00       22.00
        1700000 |          1        1.00       23.00
        1800000 |          1        1.00       24.00
        1900000 |          1        1.00       25.00
        2100000 |          1        1.00       26.00
        2200000 |          1        1.00       27.00
        2400000 |          1        1.00       28.00
        2600000 |          1        1.00       29.00
        2700000 |          1        1.00       30.00
        2900000 |          1        1.00       31.00
        3100000 |          1        1.00       32.00
        3300000 |          1        1.00       33.00
        3600000 |          1        1.00       34.00
        3800000 |          1        1.00       35.00
        4100000 |          1        1.00       36.00
        4400000 |          1        1.00       37.00
        4700000 |          1        1.00       38.00
        5000000 |          1        1.00       39.00
        5400000 |          1        1.00       40.00
        5800000 |          1        1.00       41.00
        6200000 |          1        1.00       42.00
        6600000 |          1        1.00       43.00
        7000000 |          1        1.00       44.00
        7500000 |          1        1.00       45.00
        8100000 |          1        1.00       46.00
        8600000 |          1        1.00       47.00
        9200000 |          1        1.00       48.00
        9900000 |          1        1.00       49.00
       1.05e+07 |          1        1.00       50.00
       1.13e+07 |          1        1.00       51.00
       1.21e+07 |          1        1.00       52.00
       1.29e+07 |          1        1.00       53.00
       1.38e+07 |          1        1.00       54.00
       1.48e+07 |          1        1.00       55.00
       1.58e+07 |          1        1.00       56.00
       1.69e+07 |          1        1.00       57.00
       1.80e+07 |          1        1.00       58.00
       1.93e+07 |          1        1.00       59.00
       2.06e+07 |          1        1.00       60.00
       2.21e+07 |          1        1.00       61.00
       2.36e+07 |          1        1.00       62.00
       2.52e+07 |          1        1.00       63.00
       2.70e+07 |          1        1.00       64.00
       2.88e+07 |          1        1.00       65.00
       3.08e+07 |          1        1.00       66.00
       3.30e+07 |          1        1.00       67.00
       3.53e+07 |          1        1.00       68.00
       3.77e+07 |          1        1.00       69.00
       4.03e+07 |          1        1.00       70.00
       4.31e+07 |          1        1.00       71.00
       4.61e+07 |          1        1.00       72.00
       4.93e+07 |          1        1.00       73.00
       5.27e+07 |          1        1.00       74.00
       5.63e+07 |          1        1.00       75.00
       6.02e+07 |          1        1.00       76.00
       6.44e+07 |          1        1.00       77.00
       6.88e+07 |          1        1.00       78.00
       7.36e+07 |          1        1.00       79.00
       7.87e+07 |          1        1.00       80.00
       8.42e+07 |          1        1.00       81.00
       9.00e+07 |          1        1.00       82.00
       9.62e+07 |          1        1.00       83.00
       1.03e+08 |          1        1.00       84.00
       1.10e+08 |          1        1.00       85.00
       1.18e+08 |          1        1.00       86.00
       1.26e+08 |          1        1.00       87.00
       1.34e+08 |          1        1.00       88.00
       1.44e+08 |          1        1.00       89.00
       1.54e+08 |          1        1.00       90.00
       1.64e+08 |          1        1.00       91.00
       1.76e+08 |          1        1.00       92.00
       1.88e+08 |          1        1.00       93.00
       2.01e+08 |          1        1.00       94.00
       2.15e+08 |          1        1.00       95.00
       2.30e+08 |          1        1.00       96.00
       2.45e+08 |          1        1.00       97.00
       2.62e+08 |          1        1.00       98.00
       2.81e+08 |          1        1.00       99.00
       3.00e+08 |          1        1.00      100.00
    ------------+-----------------------------------
          Total |        100      100.00
    Last edited by Nick Cox; 14 Feb 2017, 02:34.

    Comment


    • #3
      Thank you, Dr. Nicholas Cox. I'll try those.

      Comment

      Working...
      X