I am needing to create line graphs showing trends in shootings across years. Below is a table of what I assume the data should look like:
(my apologies, the table will not separate fatal and nonfatal In this window; however, fatal is the first 2 numbers and nonfatal the last 3)
I should create two variables sorted by year (1) for fatal shootings and (2) for nonfatal shootings. My data should be representative of the above table by the respective shooting types. In order to do this, I used the following code (this is for fatal shootings):
bysort year_r: egen totalftl= total(shottype) if shottype==1
Unfortunately, the results I get do not match the above tabulated values. The results are as follows:
Does anyone have any suggestions as to how I can fix this code?
Best,
Courtney
RECODE of | Type | |
year | FATAL NONFATAL | Total |
2015 | 57 437 | 494 |
2016 | 53 392 | 445 |
2017 | 61 360 | 421 |
2018 | 50 284 | 334 |
2019 | 60 310 | 370 |
2020 | 87 436 | 523 |
2021 | 84 363 | 447 |
2022 | 64 350 | 414 |
2023 | 68 363 | 431 |
2024 | 61 308 | 369 |
Total | 645 3,603 | 4,248 |
I should create two variables sorted by year (1) for fatal shootings and (2) for nonfatal shootings. My data should be representative of the above table by the respective shooting types. In order to do this, I used the following code (this is for fatal shootings):
bysort year_r: egen totalftl= total(shottype) if shottype==1
Unfortunately, the results I get do not match the above tabulated values. The results are as follows:
totalftl | ||||
Freq | percent | valid | ||
9 | 9 | 0.21 | 1.38 | 1.38 |
50 | 50 | 1.17 | 7.65 | 9.02 |
53 | 53 | 1.24 | 8.10 | 17.13 |
57 | 57 | 1.33 | 8.72 | 25.84 |
60 | 60 | 1.40 | 9.17 | 35.02 |
61 | 122 | 2.85 | 18.65 | 53.67 |
64 | 64 | 1.50 | 9.79 | 63.46 |
68 | 68 | 1.59 | 10.40 | 73.85 |
84 | 84 | 1.96 | 12.84 | 86.70 |
87 | 87 | 2.03 | 13.30 | 100.00 |
Total | 654 | 15.29 | 100.00 | |
Missing . | 3624 | 84.71 | ||
Total | 4278 | 100.00 | ||
Best,
Courtney
Comment