Announcement

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

  • Generate Stata figures

    Dear Members,
    I have about 120 firm and their profit from 2000 to 2005. I wanted to produce a figure for each firm showing profits across years (120 firm), I understand this may not be achieved, all firm on the same graph, due to the volume of firms, so perhaps for each year e.g., 2000, could you please help produce a profit figure for each firm and then use graph combine across years?
    Some of the firms are classified as treated and others not, when showing profit figures for all firms I want indicate this differences for readers either, could it be possible to distinguish them too? My example data is below for a few firms:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 firmid double profit byte treated int year
    "AR0AK"  220395.7 1 2000
    "AR0AK"    313381 1 2001
    "AR0AK"  249354.8 1 2002
    "AR0AK"  82132.36 1 2003
    "AR0AK"    382776 1 2004
    "AR0AK"  163354.1 1 2005
    "BR0BVC" 435587.7 0 2000
    "BR0BVC" 135307.4 0 2001
    "BR0BVC" 226760.7 0 2002
    "BR0BVC" 326662.4 0 2003
    "BR0BVC" 17160.59 0 2004
    "BR0BVC" 92317.18 0 2005
    "R1FFGD" 105036.4 0 2000
    "R1FFGD"  17561.9 0 2001
    "R1FFGD" 14266.74 0 2002
    "R1FFGD" 41505.04 0 2003
    "R1FFGD" 22411.66 0 2004
    "R1FFGD" 44408.66 0 2005
    "HR1HJ"  273056.4 0 2000
    "HR1HJ"  297363.7 0 2001
    "HR1HJ"  345254.6 0 2002
    "HR1HJ"  117554.2 0 2003
    "HR1HJ"  227174.3 0 2004
    "HR1HJ"  268282.2 0 2005
    "KKHR1K" 245748.8 1 2000
    "KKHR1K" 252903.4 1 2001
    "KKHR1K" 263120.6 1 2002
    "KKHR1K" 91086.77 1 2003
    "KKHR1K" 150623.9 1 2004
    "KKHR1K" 304408.5 1 2005
    "RA2KLN" 391936.8 1 2000
    "RA2KLN" 443126.1 1 2001
    "RA2KLN"   254274 1 2002
    "RA2KLN" 262773.8 1 2003
    "RA2KLN" 7412.984 1 2004
    "RA2KLN" 31175.81 1 2005
    "OORA4"  95980.02 0 2000
    "OORA4"  61125.71 0 2001
    "OORA4"  44418.77 0 2002
    "OORA4"  11390.06 0 2003
    "OORA4"  25359.23 0 2004
    "OORA4"  31621.72 0 2005
    "GRIBD"  9115.004 0 2000
    "GRIBD"  30519.15 0 2001
    "GRIBD"  29628.02 0 2002
    "GRIBD"  51302.41 0 2003
    "GRIBD"  72216.11 0 2004
    "GRIBD"  31126.67 0 2005
    "T0RA7"  252923.8 1 2000
    "T0RA7"  175159.1 1 2001
    "T0RA7"  265289.7 1 2002
    "T0RA7"  111411.3 1 2003
    "T0RA7"   69474.7 1 2004
    "T0RA7"  312690.4 1 2005
    "BRAEEO" 127901.5 0 2000
    "BRAEEO" 134289.1 0 2001
    "BRAEEO" 192778.9 0 2002
    "BRAEEO" 10809.42 0 2003
    "BRAEEO" 206644.5 0 2004
    "BRAEEO" 328594.1 0 2005
    "ORAJOO" 318819.3 1 2000
    "ORAJOO" 371784.6 1 2001
    "ORAJOO" 33836.87 1 2002
    "ORAJOO" 116244.3 1 2003
    "ORAJOO" 264327.8 1 2004
    "ORAJOO" 286003.7 1 2005
    "RALLAK" 239140.4 0 2000
    "RALLAK" 287357.4 0 2001
    "RALLAK" 118713.4 0 2002
    "RALLAK" 122370.7 0 2003
    "RALLAK" 270709.2 0 2004
    "RALLAK" 231136.3 0 2005
    "RANYWL" 208882.5 0 2000
    "RANYWL" 154052.5 0 2001
    "RANYWL" 116866.3 0 2002
    "RANYWL" 179304.7 0 2003
    "RANYWL" 206068.1 0 2004
    "RANYWL" 86758.95 0 2005
    "RAPUIO" 105751.7 1 2000
    "RAPUIO" 142543.8 1 2001
    "RAPUIO" 47128.23 1 2002
    "RAPUIO" 179498.7 1 2003
    "RAPUIO" 117755.8 1 2004
    "RAPUIO" 97470.84 1 2005
    end
    I would be happy to clarify should you have any question.

    Best regards

  • #2
    Code:
    levelsof firmid, local(firmids)
    local tocombine
    local g = 1
    foreach f of local firmids {
        summ treated if firmid == "`f'", meanonly
        local treatment `r(mean)'
        local color = cond(`treatment', "red", "blue")
        local graph_name g`g'
        graph twoway line profit year if firmid == `"`f'"', lcolor(`color') sort ///
            title(`"`f'"')  name(g`g', replace)
        local tocombine `tocombine' g`g'
        local ++g
        
    }
    display `"`tocombine'"'
    graph combine `tocombine', nocopies

    Comment


    • #3
      Hi Clyde
      Many thanks. It would be too much to put 120 firms on the same graph that way. I wrote the following code, but can you help me improve readability of firmid on the graph?
      Code:
      twoway (scatter profit year if treated==1, sort mcolor(ltblue) msize(3-pt) msymbol(triangle) mlabel(firmid) mlabsize(vsmall) mlabcolor(ltblue) mlabgap(small)) ///
                   (scatter profit year if treated==0, sort mcolor(bluishgray8) msize(3-pt) msymbol(circle) mlab(firmid) mlabsize(vsmall) mlabcolor(bluishgray8)), yline(3500, lwidth(medthin) lpattern(dash)) by(, legend(on span)) legend(order(1 "treated" 2 "control")) by(treated)
      Alternatively, can graph bar be used to produce for each firm in each group and then graph combine?

      Thank you for your help!
      Last edited by Tariku Getaneh; 04 Nov 2024, 05:36.

      Comment


      • #4
        If you have 120 different identifiers as marker labels, only those with extreme values on profit will be legible.

        You might make some small progress by omitting the markers themselves.

        This is a mess with 74 identifiers, and yours is unlikely to be better.

        Code:
         sysuse auto, clear
        (1978 automobile data)
        
        . scatter price rep78, ms(none) mla(make) mlabpos(0)
        Click image for larger version

Name:	mess.png
Views:	1
Size:	156.9 KB
ID:	1766948

        Comment


        • #5
          Thank you Nick. That is right, mine would be any better. Can we produce a figure for each group (firms) by year. For instance, in one graph for the treated: the y axis will be profit and the xaxis will be firms ids. then I will have have five lines on the figure one for each year. I will do the same for control group. I will then combine both figures or I will leave it separate if combining makes things worse. Can this be achieved ?

          Comment


          • #6
            Sorry, but I can't follow what you want. I can't imagine any design that shows 120 identifiers legibly, but that may be my lack of imagination.

            Your dataset of 720 observations is not too large to post here.

            Comment


            • #7
              Thank you Nick, my dataset is in a managed setting, I cannot extract it. The ones I provided is hand typed based on the actual dataset. For instance, in excel I was able to produce column stacked profit for each firm, this well readable. the xaxis is the firmids, and the yaxis is profit. I produced a bar with different colors assigned to each year profits. Can this be done in Stata too?

              Comment


              • #8
                Stacked bar charts are certainly possible in Stata.

                Code:
                help graph bar
                How would you deal with loss (negative profit)? I am interested to know how Excel makes such plots readable.

                Comment

                Working...
                X