Announcement

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

  • How can I merge data within a Dataset?

    Hallo Stata Community,
    I want to merge Data from my dataset together, but I just don't know how: Click image for larger version

Name:	Screenshot 2022-10-01 at 15.08.32.png
Views:	1
Size:	73.0 KB
ID:	1683927
    In the picture, you see my Dataset. I now want to put the variables with the directtax ==1 together in a group and the variable directtax == 0 in another group. My aim is to create only one year with the cumulative numbers in the value section, that I have for each year two groups: one group with the directtax==1 and the cumulative number of the values (0+44.517+137.834) and another group with directtax==0 and the cumulative number of the values within a year.

    I hope you can help me,

    kind regards and thank you in advance

    Lucas

  • #2
    Let me start with the following advice about effectively using Statalist.

    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 is 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.

    When you present your example data as a picture, most members will move on to the next post, because who really wants to type example data from a picture to use to develop the code?

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem. Thank you in advance for following the guidance from the FAQ on your future posts.

    With that said, the following seems to do what you describe.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(tax year) str3 unitcode str9 unit long value byte(country directtax)
    3000 1970 "USD" "US Dollar"      0 3 1
    5000 1970 "USD" "US Dollar"  55213 3 0
    2000 1970 "USD" "US Dollar"  44517 3 1
    1000 1970 "USD" "US Dollar" 137834 3 1
    5000 1990 "USD" "US Dollar" 177328 3 0
    1000 1990 "USD" "US Dollar" 701731 3 1
    end
    
    collapse (sum) value, by(country year directtax)
    list, clean noobs abbreviate(12)
    Code:
    . list, clean noobs abbreviate(12)
    
        year   country   directtax    value  
        1970         3           0    55213  
        1970         3           1   182351  
        1990         3           0   177328  
        1990         3           1   701731

    Comment

    Working...
    X