Announcement

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

  • percentile graph based on event time

    Dear Statausers

    I have the following dataset, where I have municipality (kom_kod), redovar (year), number of office (office_WS), number of caseworkers working at offices (CW_WS), closeyear (closing year of municipality offices) and event time (0 means when the municipality office closes down):

    [CODE]
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int kom_kod float redovar double(office_WS CW_WS) int closeyear float event_time
    115 2005 1 7 2015 -10
    115 2006 1 12 2015 -9
    115 2007 1 9 2015 -8
    115 2008 1 3 2015 -7
    115 2009 1 3 2015 -6
    115 2010 1 4 2015 -5
    115 2011 1 3 2015 -4
    115 2012 1 4 2015 -3
    115 2013 1 3 2015 -2
    115 2014 1 3 2015 -1
    115 2015 1 3 2015 0
    115 2016 0 0 2015 1
    115 2017 0 0 2015 2
    115 2018 0 0 2015 3
    117 2005 1 6 2016 -11
    117 2006 1 8 2016 -10
    117 2007 1 7 2016 -9
    117 2008 1 7 2016 -8
    117 2009 1 6 2016 -7
    117 2010 1 11 2016 -6
    117 2011 1 12 2016 -5
    117 2012 1 23 2016 -4
    117 2013 1 19 2016 -3
    117 2014 1 16 2016 -2
    117 2015 1 14 2016 -1
    117 2016 1 1 2016 0
    117 2017 0 0 2016 1
    117 2018 0 0 2016 2
    125 2005 1 3 2015 -10
    125 2006 1 3 2015 -9
    125 2007 1 2 2015 -8
    125 2008 1 2 2015 -7
    125 2009 1 2 2015 -6
    125 2010 1 3 2015 -5
    125 2011 0 0 2015 -4
    125 2012 0 0 2015 -3
    125 2013 1 1 2015 -2
    125 2014 1 1 2015 -1
    125 2015 1 2 2015 0
    125 2016 0 0 2015 1
    125 2017 0 0 2015 2
    125 2018 0 0 2015 3
    139 2005 2 4 2015 -10
    139 2006 2 4 2015 -9
    139 2007 2 2 2015 -8
    139 2008 0 0 2015 -7
    139 2009 0 0 2015 -6
    139 2010 0 0 2015 -5
    139 2011 0 0 2015 -4
    139 2012 0 0 2015 -3
    139 2013 0 0 2015 -2
    139 2014 0 0 2015 -1
    139 2015 0 0 2015 0
    139 2016 0 0 2015 1
    139 2017 0 0 2015 2
    139 2018 0 0 2015 3
    192 2005 1 5 2017 -12
    192 2006 1 6 2017 -11
    192 2007 1 8 2017 -10
    192 2008 1 2 2017 -9
    192 2009 1 2 2017 -8
    192 2010 1 6 2017 -7
    192 2011 1 4 2017 -6
    192 2012 1 2 2017 -5
    192 2013 1 3 2017 -4
    192 2014 1 3 2017 -3
    192 2015 1 10 2017 -2
    192 2016 1 6 2017 -1
    192 2017 1 5 2017 0
    192 2018 1 4 2017 1
    305 2005 1 2 2016 -11
    305 2006 1 2 2016 -10
    305 2007 1 3 2016 -9
    305 2008 1 4 2016 -8
    305 2009 1 5 2016 -7
    305 2010 0 0 2016 -6
    305 2011 1 4 2016 -5
    305 2012 1 5 2016 -4
    305 2013 1 4 2016 -3
    305 2014 1 3 2016 -2
    305 2015 1 9 2016 -1
    305 2016 1 4 2016 0
    305 2017 1 1 2016 1
    305 2018 0 0 2016 2



    I have done the some event time figures using the following code:

    keep if inrange(event_time,-5,5)
    gcollapse (mean) CW_WS office_WS, by(event_time)
    label var CW_WS "average CW and PES office"
    *label var office_WS "average PES office"
    grstyle init
    grstyle set plain, dot horizontal grid

    twoway (line CW_WS event_time, legend(off) yaxis(1) ) ///
    , graphregion(color(white)) plotregion(color(white)) xline(0, lcolor(black) lpattern(dash)) graphregion(color(white)) name(a, replace) ///
    title("Average CW per kommun-year", size(small)) subtitle("(for kommun closed between 2014-2017)", size(small))
    graph save "$figures/CW_WS.gph", replace

    twoway (line office_WS event_time, legend(off) yaxis(1)) ///
    , graphregion(color(white)) plotregion(color(white)) xline(0, lcolor(black) lpattern(dash)) graphregion(color(white)) name(b, replace) ///
    title("Average office_WS per kommun", size(small)) subtitle("(for kommun closed between 2014-2017)", size(small))
    graph save "$figures/office_WS.gph", replace


    grc1leg "$figures/CW_WS.gph" "$figures/office_WS.gph"
    graph export "$figures/CW_and_PES_office_WS.pdf", replace





    Now, I want to do this graph for 20th percentile group of the distribution. I am pretty unclear about how to do that. Any help would be highly appreciated.

    Thanks,

    Zariab Hossain
    Uppsala University

  • #2
    Maybe instead of mean collapse on p20.

    or else use pctile to dummy them out and then "if" on collapse.

    Comment


    • #3
      Thanks George for the tip. I also did this and got what I wanted.

      Comment

      Working...
      X