Announcement

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

  • how to use bysort with function total and tab

    I have data include varables ( year , Event_Type , Loss_Amount__USD )

    I want state to to sort the data by year , and with the year table I need the total of Loss_Amount__USD within that year for each year soeritly

    I tried to do : bysort Settlement_Year: tab BIS_Event_Type___Level_1 , Total Loss_Amount__USD__Millions_
    but that didn't work

    Click image for larger version

Name:	image_21433.png
Views:	1
Size:	27.2 KB
ID:	1594950

    my data looks like :
    Click image for larger version

Name:	image_21434.png
Views:	1
Size:	44.2 KB
ID:	1594962
    Last edited by Noah baa; 24 Feb 2021, 19:11.

  • #2
    Perhaps something like the following will start you in a helpful direction
    Code:
    table BIS_Event_Type___Level_1 year, c(sum Loss_Amount__USD__Millions_)

    Comment


    • #3
      it works, thank you

      but still, I need to add the frequency as a column in the table

      Click image for larger version

Name:	Screenshot 2021-02-25 165640.png
Views:	1
Size:	14.6 KB
ID:	1595104
      Attached Files
      Last edited by Noah baa; 25 Feb 2021, 14:57.

      Comment


      • #4
        You wrote in post #1

        I have data include varables ( year , Event_Type , Loss_Amount__USD )
        I noticed that your tab command in that post had longer versions of the names of Event_Type and Loss_Amount__USD and I used those longer variable names, rather than the ones you gave in the quoted passage, in my example code in post #2.

        You should now be able to figure out how to correct the code that "doesn't work" from post #2 using the error message Stata gave and your knowledge of your variable names.

        Some advice for future posts: screenshots are less useful than you might imagine them to be. Please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

        The more you help others understand your problem, the more likely others are to be able to help you solve your problem.
        Last edited by William Lisowski; 25 Feb 2021, 14:59.

        Comment

        Working...
        X