Announcement

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

  • Issue : bysort x (y) : egen newvar = sum(z )

    Hi All
    I want to sum variable by sorting two variables as see my sample data set in below ;
    I used the code :
    bysort userphoneno(actiondescription): egen double sum_subsection=sum(dif_min)

    but sum_subsection is summary of all observations and really I want to get sum of observation within same 'actiondescription' ,
    Please suggest me like according to 'actiondescription' variable , sum of ""Baby_ProdcutDetail" for 'dif_min' .
    There is different observation under 'userphoneno' variable.



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str11 userphoneno str22 actiondescription float dif_min double sum_subsection
    "09424319384" "Baby_ProdcutDetail"      .08333334 48.833333510905504
    "09424319384" "Baby_ProdcutDetail"      .26666668 48.833333510905504
    "09424319384" "Baby_ProdcutDetail"            .65 48.833333510905504
    "09424319384" "Baby_ProdcutDetailItem"         .2 48.833333510905504
    "09424319384" "Baby_ProdcutDetailItem"  .11666667 48.833333510905504
    "09424319384" "ChatConversation"                0 48.833333510905504
    "09424319384" "ChatConversation"        1.1833333 48.833333510905504
    "09424319384" "ChatConversation"        .08333334 48.833333510905504
    "09424319384" "ChatRoom"                      .05 48.833333510905504
    "09424319384" "ChatRoom"               .016666668 48.833333510905504
    "09424319384" "Dashboard"               .06666667 48.833333510905504
    "09424319384" "Dashboard"              .033333335 48.833333510905504
    "09424319384" "Dashboard"              .016666668 48.833333510905504
    "09424319384" "Dashboard"                     .05 48.833333510905504
    "09424319384" "Dashboard"                     .05 48.833333510905504
    "09424319384" "Dashboard"               .06666667 48.833333510905504
    "09424319384" "DoctorLocator"                  .2 48.833333510905504
    "09424319384" "DoctorLocator"           .26666668 48.833333510905504
    "09424319384" "DoctorLocatorList"       .21666667 48.833333510905504
    "09424319384" "InAppNotification"               0 48.833333510905504
    "09424319384" "InAppNotification"      .016666668 48.833333510905504
    "09424319384" "LessonChoose"            1.9333333 48.833333510905504
    "09424319384" "LessonChoose"            1.2166667 48.833333510905504
    "09424319384" "LessonChoose"                 1.75 48.833333510905504
    "09424319384" "NewsFeed"                .06666667 48.833333510905504
    "09424319384" "NewsFeed"               .016666668 48.833333510905504
    "09424319384" "NewsFeed"               .016666668 48.833333510905504
    "09424319384" "NewsFeed"                 .7166666 48.833333510905504
    "09424319384" "NewsFeed"                        0 48.833333510905504
    "09424319384" "NewsFeed"                .06666667 48.833333510905504
    "09424319384" "NewsFeed"                 .8666667 48.833333510905504
    "09424319384" "NewsFeed"                       .1 48.833333510905504
    "09424319384" "ProviderDetail"           5.016667 48.833333510905504
    "09424319384" "Quiz"                     .3333333 48.833333510905504
    "09424319384" "Quiz"                   .033333335 48.833333510905504
    "09424319384" "Quiz"                          .15 48.833333510905504
    "09424319384" "Quiz"                   .016666668 48.833333510905504
    "09424319384" "Quiz"                    .13333334 48.833333510905504
    "09424319384" "Referral"                       .3 48.833333510905504
    "09424319384" "Referral"                      .05 48.833333510905504
    "09424319384" "Referral"                .08333334 48.833333510905504
    "09424319384" "Reminder"                .08333334 48.833333510905504
    "09424319384" "Save_Post"               .08333334 48.833333510905504
    "09424319384" "Settings"                       30 48.833333510905504
    "09424319384" "Settings"                       .9 48.833333510905504
    "09424319384" "Settings"                        0 48.833333510905504
    "09424319384" "Shopping"                       .4 48.833333510905504
    "09424319384" "Symptoms"                       .1 48.833333510905504
    "09424319384" "WeeklyMessage"            .7666667 48.833333510905504
    end

  • #2
    If you eliminate the parentheses that are around (actiondescription) in your command, you will get what you are asking for.

    Comment


    • #3
      Hi Clyde ,

      I got the answer , I removed parentheses , it could works , and thanks for that !

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str11 userphoneno str22 actiondescription float dif_min double sum_subsection float sr_subsecion
      "09250680061" "Dashboard"             0                  0 1
      "09250680061" "Entry"          .3666667 .36666667461395264 1
      "09250680061" "NewsFeed"      .18333334 1.3833333682268858 1
      "09250680061" "NewsFeed"     .016666668 1.3833333682268858 2
      "09250680061" "NewsFeed"             .6 1.3833333682268858 3
      "09250680061" "NewsFeed"            .05 1.3833333682268858 4
      "09250680061" "NewsFeed"      .28333333 1.3833333682268858 5
      "09250680061" "NewsFeed"      .16666667 1.3833333682268858 6
      "09250680061" "NewsFeed"      .08333334 1.3833333682268858 7
      "09250680061" "Notification"          0  .8999999761581421 1
      "09250680061" "Notification"         .9  .8999999761581421 2
      end

      Comment

      Working...
      X