Announcement

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

  • Deleting unnecessary rows

    Hello, I have created group mean for each region using "bys subregion: egen meanvalue= mean(activity)", but now I am left with multiple observations for each row, which I want to get rid off. This is:

    subregion meanvalue
    regiona 0.184292
    regiona 0.184292
    regiona 0.184292
    regiona 0.184292
    regiona 0.184292
    regionb 0.444332
    regionb 0.444332
    regionb 0.444332
    regionb 0.444332
    regionb 0.444332
    I have this for many regions. just want to have one row per region, is there a straightforward to do this in stata? Thanks.

  • #2
    Alexa:
    welcome to thsi forum.
    You may want to try:
    Code:
    . input str20 subregion meanvalue
    
                    subregion  meanvalue
      1. regiona 0.184292
      2. regiona 0.184292
      3. regiona 0.184292
      4. regiona 0.184292
      5. regiona 0.184292
      6. regionb 0.444332
      7. regionb 0.444332
      8. regionb 0.444332
      9. regionb 0.444332
     10. regionb 0.444332
     11. end
    
    
    . bysort subregion: drop if _n>1
    
    
    . list
    
         +---------------------+
         | subreg~n   meanva~e |
         |---------------------|
      1. |  regiona    .184292 |
      2. |  regionb    .444332 |
         +---------------------+
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Thank you very much! Really appreciate it.

      Comment

      Working...
      X