Announcement

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

  • creating a histogram

    Hello there:
    Q: I would like to create a histogram showing the PROPORTION OF CAR MECHANICS vs the mean no of CAR repairs done per year, PER car mechanic

    See picture:
    Click image for larger version

Name:	Screenshot 2023-08-10 at 14.17.53.png
Views:	1
Size:	1.62 MB
ID:	1723448




    **Repair - if a repair was performed (1) or not (0)
    **Totaldoneperyear - total no of repairs performed each year generated from:

    Code:
    bys mechanic repairyear: egen totaldoneperyear=sum(repair)
    Code:
    clear
    input float(repair repairdate) str1 mechanic float(repairyear totaldoneperyear)
    1 14610 "1" 2000 1
    0 15310 "1" 2001 0
    1 15745 "1" 2003 1
    0 16109 "1" 2004 0
    0 16468 "1" 2005 0
    1 17867 "2" 2008 1
    0 17932 "2" 2009 0
    1 18298 "2" 2010 2
    1 18303 "2" 2010 2
    1 19029 "2" 2012 1
    end
    format %td repairdate


    I've tried this:

    Code:
    histogram totaldoneperyear, freq by(mechanic)
    However this generates differ panels for each mechanic. I would like them all in one panel as seen above (in my very amateurish drawing)
    Can anyone help?
    Last edited by Martin Imelda Borg; 10 Aug 2023, 07:26.

  • #2
    drop the by

    Comment


    • #3
      Actually found an alternative to

      Code:
      collapse (mean) repair, by (mechanic)
      histogram repair, freq
      is there another alternative to -collapse- ?
      -> this code : generates the average no of repairs done by the mechanic throughout the study period and gives each mechanic ONE row only

      if I leave the code as post #1 I only have the ‘total number’ done by the mechanic which if the mechanic does 2 repairs in 1990 as there are 2 rows for 1990, the histogram from post #1 will present this as a total of 4 (as you can see in the data)

      just wondering if there is an alternative to -collapse- to generate the average number of repairs done by the mechanic throughout the study period and rom that plotting a histogram with the frequency of mechanics performing average repairs per year

      not sure if I made myself clear?

      Comment


      • #4
        bys mechanic: g mechanicN = _n
        egen repair_m = mean(repair), by(mechanic)
        hist repair_m if mechanicN==1, freq

        Comment

        Working...
        X