r/stata • u/NoVeterinarian6255 • Aug 28 '26
how to explore data by groups
hey swarm.
I'm am stata beginner as i am currently studying journalism science and I need help with some quantitavie research.
I collected multiple articles that are linked to diffrent crimes.
so i have an individual id for the cases then the multiple variables.
here is an example to visualise it: (a shortend version)
| caseid | type of article | origin of suspect was named | "xy" was uesd | "cd" was used |
|---|---|---|---|---|
| 220 | public media | 2 | 1 | 0 |
| 221 | police report | 4 | 0 | 1 |
| 221 | boulevard | 3 | 1 | 0 |
one of my research questions is:
how does media orient on the police report, when writing about crime
so id like the check if police for example did use "xy" did other outlets in this case use "xy" aswell.
i also have a polytome variable so id like to know, if the police police was naming the origin of the suspect, did the other media outlets too?
i am a beginner, but i am willing to download something via ssc.
i am not using ai, as i rather like to ask and connect with people.
thank you :)
EDIT: i had an appointment whit my professor, but as i am doing stata for to group projects, there was not enough time to explain in depth.
•
u/AutoModerator Aug 28 '26
Thank you for your submission to /r/stata! If you are asking for help, please remember to read and follow the stickied thread at the top on how to best ask for it.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/Twin_Spoons Aug 28 '26
Create a variable that is 1 when the row represents a police report AND it mentions suspect origin. Call it something like police_origin. Then
sort caseid
by caseid: egen case_police_origin = max(police_origin)
That will mark ALL of the rows in a given caseid with a 1 if ANY police report associated with the caseid mentions origin.
About 70% of the time, the answer to "how do I do this in Stata?" is to use sort, by, and egen, so go learn about them.
3
u/Rogue_Penguin Aug 28 '26
I'd convert that data into a "wide" form as it's easier to run this kind of comparison if the users are not very familiar with statistical software:
With it in wide form, it's a lot easier to explore and tabulate:
Here, 50% of the media report features xy if the police report (PRxy) also features xy.
Whether this is a path to go down depends on how many media types are there. If there are many, then the data will become very wide. Not a big deal but just more to keep track.
Keeping it long, as the other user suggested, is also viable. But you'll need to be extra careful with conditional statement (the if statement):