Announcement

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

  • summarize by year and type

    Hey Guys,

    I have never posted here but the answers in this forum have already helped me a lot in the past I did not find an answer to the question in the title so please forgive me if this has been discussed already. It probably has. Sometimes my limited understanding of stata makes it hard for me to actually understand the problems and solutions discussed here.

    Anyway: I have a dataset that contains observations on criminal court proceedings from years 2011 and 2017 (var "Jahrgang"); each row will be one case. I grouped the cases according to the type of crime committed (var "deliktsart") (e.g. gang theft, Tax evasion, robbery, fraud) and also calculated the number of days it took to have them resolved in court (var "AnzahlHVTage").

    Now I would like know, whether the mean number of court days regarding the different groups of crimes has changed between 2011 and 2017.

    I came up with

    by Jahrgang, sort: summarize AnzahlHVTage if deliktsart==4

    but this only allows me to compare the means for one single type of crime.

    by Jahrgang deliktsart, sort: summarize AnzahlHVTage

    will give me a really long table that contains all the information I am looking for but does not provide a good overview.

    Is there any way to have stata produce a table that shows the different crime-groups and the mean number of court-days for 2011 and 2017 like so:

    deliktsart mean nr of court days in 2011 mean nr of court days in 2017
    1.
    2.
    4.

    I tried calculating the mean number of court days per group but this also did not provide me with a feasible solution...also I had the impression that there has to be a simpler solution to my problem.

    bysort deliktsart: egen mean_anz_hv_tage_by_delikt_2011 = mean(AnzahlHVTage) if Jahrgang == 2011
    bysort deliktsart: egen mean_anz_hv_tage_by_delikt_2017 = mean(AnzahlHVTage) if Jahrgang == 2017

    generate mean_anz_hv_tage_by_year=mean_anz_hv_tage_by_delik t_2011
    replace mean_anz_hv_tage_by_year=mean_anz_hv_tage_by_delik t_2017 if (mean_anz_hv_tage_by_year==.)
    replace mean_anz_hv_tage_by_year=.a if (mean_anz_hv_tage_by_year==.)


    Any help on this will be very much appreciated!

    Also please forgive me if this has been discussed before and I did not find the solution myself.

    Lastly please excuse my english since I am not a native speaker



    This is a snippet of my original dataset (in German):



    deliktsart Jahrgang Anzahl~e

    76. | 8. Bandendiebstahl 2011. 2011 14 |
    77. | 11. Steuerhinterziehung 2011. 2011 . |
    78. | 6. Menschenraub 2011. 2011 2 |
    79. | 5. Betrugsdelikte 2011. 2011 2 |
    80. | 1. Tötungsdelikte 2011. 2011 6 |
    |-----------------------------------------------------------------|
    81. | 3. Raubdelikte 2011. 2011 3 |
    82. | 4. BtM-Delikte 2011. 2011 1 |
    83. | 5. Betrugsdelikte 2011. 2011 15 |
    84. | 3. Raubdelikte 2011. 2011 4 |
    85. | 4. BtM-Delikte 2011. 2011 1 |
    |-----------------------------------------------------------------|
    86. | 2. KV-Delikte 2011. 2011 3 |
    87. | 5. Betrugsdelikte 2011. 2011 . |
    88. | 5. Betrugsdelikte 2011. 2011 15 |
    89. | 5. Betrugsdelikte 2011. 2011 15 |
    90. | 4. BtM-Delikte 2011. 2011 3 |
    |-----------------------------------------------------------------|
    91. | 8. Bandendiebstahl 2011. 2011 . |
    92. | 4. BtM-Delikte 2011. 2011 . |
    93. | 3. Raubdelikte 2011. 2011 . |
    94. | 4. BtM-Delikte 2011. 2011 1 |
    95. | 7. Bedrohung 2011. 2011 . |
    |-----------------------------------------------------------------|
    96. | 16. Gemeinschädl Sachbesch 2011. 2011 . |
    97. | 8. Bandendiebstahl 2011. 2011 62 |
    98. | 4. BtM-Delikte 2011. 2011 5 |
    99. | 10. Sonst. Delikte (22. Abschnitt StGB) 2017. 2017 . |
    100. | 1. Tötungsdelikte 2017. 2017 76 |
    |-----------------------------------------------------------------|
    101. | 4. BtM-Delikte 2017. 2017 2 |
    102. | 13. Waffenrechtliche Verstöße 2017. 2017 . |
    103. | 9. Sexualdelikte 2017. 2017 . |
    104. | 3. Raubdelikte 2017. 2017 3 |
    105. | 1. Tötungsdelikte 2017. 2017 19 |
    |-----------------------------------------------------------------|
    106. | 3. Raubdelikte 2017. 2017 1 |
    107. | 2. KV-Delikte 2017. 2017 3 |
    108. | 4. BtM-Delikte 2017. 2017 4 |
    109. | 4. BtM-Delikte 2017. 2017 . |
    110. | 4. BtM-Delikte 2017. 2017 51 |
    |-----------------------------------------------------------------|
    111. | 19. Schwere Brandstiftung 2017. 2017 . |
    112. | 3. Raubdelikte 2017. 2017 6 |




  • #2

    Code:
    * Stata 17
    table deliktsart Jahrgang if inlist(Jahrgang, 2011, 2017), statistic(mean AnzahlHVTage)
    
    * version 16 and back a while
    table deliktsart Jahrgang if inlist(Jahrgang, 2011, 2017), c(mean AnzahlHVTage)
    Last edited by Nick Cox; 02 Mar 2022, 08:59.

    Comment


    • #3
      Hi Nick,

      thank you so much! Highly appreciated!

      Cheers!

      Comment

      Working...
      X