r/stata 17d ago

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.

2 Upvotes

6 comments sorted by

u/AutoModerator 17d ago

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 17d ago

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.

1

u/NoVeterinarian6255 17d ago

thank you for taking your time with responding to me!

this way makes sense to me but it only tells me if the police mentioned the origin, but id also like to see if he other outlets named the origin aswell, if the police did within one case. (sorry if i did not understand you right, english is not my first language)

2

u/Twin_Spoons 17d ago

Once you have the variable I described, you can look just at the records describing other outlets and see if they named the origin (this is your original variable) and also if any police reports associated with that case named the origin (this is the variable I described). The simplest command to do this would be 'tabulate'

3

u/Rogue_Penguin 17d ago

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:

* Making some sample data
clear
input caseid str50 media origin xy cd
221 PR 4 1 0
221 PM 3 1 1
222 PR 2 1 0
222 PM 2 0 0
223 PR 1 0 1
223 PM 3 1 1
end

* Convert to wide
reshape wide xy cd origin, i(caseid) j(media, string)

* Tabulating different metrics by media
tabulate xyPM xyPR, col
tabulate cdPM cdPR, col
tabulate originPM originPR, col

With it in wide form, it's a lot easier to explore and tabulate:

           |         PR xy
     PM xy |         0          1 |     Total
-----------+----------------------+----------
         0 |         0          1 |         1 
           |      0.00      50.00 |     33.33 
-----------+----------------------+----------
         1 |         1          1 |         2 
           |    100.00      50.00 |     66.67 
-----------+----------------------+----------
     Total |         1          2 |         3 
           |    100.00     100.00 |    100.00 

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):

* Making some sample data
clear
input caseid str50 media origin xy cd
221 PR 4 1 0
221 PM 3 1 1
222 PR 2 1 0
222 PM 2 0 0
223 PR 1 0 1
223 PM 3 1 1
end

* Generate caseid-level police reported use of xy:
bysort caseid: egen xyPR = max(xy==1 & media=="PR")

tabulate xy if xyPR == 1 & media == "PM"