Announcement

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

  • Using binscatter intuition in a piecewise regression

    Hi. I am running a piecewise regression on a dataset with over 4,000 observations. The resultant twoway graph (below) is not helpful due to the number of observations in it. While trying to find a better way to depict my results, I came across the binscatter command. Is there anyway I can take a similar approach with my code (through binning) below, without changing the underlying method completely as I would if I were to use binscatter?

    Or, is there any other manner in which to better depict these results. Any help will be very much appreciated?



    Code:
    
    **Current code:
    
    xtset con_id week_num
    xtreg week_docalltele knot1 knot2 knot3 week1 week2 i.age_cat i.doc_desig, vce(cluster con_id)
    predict linear_spline /* Generate the predicted scores */
    
    
    *** Plot graph
    sort week_num
    tw    (scatter week_docalltele week_num , ///
        mc(gs10) msize(vsmall)     title("Hyderabad")         ///
        xline(78 114, lpattern(dash) lcol("cranberry")) ///
        xlab(40 "Pre-intervention" 95 "Mandate" 126 "Platform", noticks labsize (small)) ///
        ylab(, nogrid labsize(vsmall))     ///
        ytitle("Number of consultations")   ///
        xtitle("") scheme(s1color)  ///
        legend(region(lpattern(blank)) order(1 "observed" 2 "predicted values")) legend(size(vsmall)))    ///
        (lfit linear_spline week_num if period==0, col("navy")) ///
        (lfit linear_spline week_num if period==1, col("navy")) ///
        (lfit linear_spline week_num if period==2, col("navy"))
    
    
    
    *Data sample
    
    
    input long con_id float(week_num week_docalltele) byte(knot1 knot2 knot3) float(week1 week2 age_cat) byte doc_desig float period
     1  1  7  1 0 0 0 0 3 2 0
     4  1 17  1 0 0 0 0 2 5 0
     5  1  8  1 0 0 0 0 3 4 0
    12  1 10  1 0 0 0 0 2 1 0
    13  1 25  1 0 0 0 0 3 3 0
     1  2 15  2 0 0 0 0 3 2 0
     4  2  1  2 0 0 0 0 2 5 0
     5  2  4  2 0 0 0 0 3 4 0
    11  2 11  2 0 0 0 0 2 2 0
    12  2  8  2 0 0 0 0 2 1 0
    13  2 12  2 0 0 0 0 3 3 0
    15  2  6  2 0 0 0 0 2 2 0
     1  3 14  3 0 0 0 0 3 2 0
     4  3 20  3 0 0 0 0 2 5 0
     5  3  8  3 0 0 0 0 3 4 0
     6  3 10  3 0 0 0 0 2 5 0
    10  3  5  3 0 0 0 0 3 1 0
    11  3 11  3 0 0 0 0 2 2 0
    12  3 10  3 0 0 0 0 2 1 0
    13  3 22  3 0 0 0 0 3 3 0
    15  3  5  3 0 0 0 0 2 2 0
     1  4 11  4 0 0 0 0 3 2 0
     4  4 12  4 0 0 0 0 2 5 0
     5  4  9  4 0 0 0 0 3 4 0
     6  4 15  4 0 0 0 0 2 5 0
    11  4 12  4 0 0 0 0 2 2 0
    12  4 12  4 0 0 0 0 2 1 0
    15  4 12  4 0 0 0 0 2 2 0
     4  5  3  5 0 0 0 0 2 5 0
     5  5 11  5 0 0 0 0 3 4 0
     6  5 39  5 0 0 0 0 2 5 0
    10  5  2  5 0 0 0 0 3 1 0
    12  5  6  5 0 0 0 0 2 1 0
    13  5  6  5 0 0 0 0 3 3 0
    15  5  6  5 0 0 0 0 2 2 0
     1  6 10  6 0 0 0 0 3 2 0
     5  6 10  6 0 0 0 0 3 4 0
     6  6 23  6 0 0 0 0 2 5 0
    11  6 23  6 0 0 0 0 2 2 0
    12  6 14  6 0 0 0 0 2 1 0
    13  6 12  6 0 0 0 0 3 3 0
    15  6  3  6 0 0 0 0 2 2 0
     1  7 11  7 0 0 0 0 3 2 0
     4  7 10  7 0 0 0 0 2 5 0
     5  7 11  7 0 0 0 0 3 4 0
     6  7 31  7 0 0 0 0 2 5 0
    12  7  8  7 0 0 0 0 2 1 0
    13  7 25  7 0 0 0 0 3 3 0
    15  7 12  7 0 0 0 0 2 2 0
     1  8 13  8 0 0 0 0 3 2 0
     4  8 10  8 0 0 0 0 2 5 0
     5  8  6  8 0 0 0 0 3 4 0
    11  8 17  8 0 0 0 0 2 2 0
    13  8 13  8 0 0 0 0 3 3 0
    15  8  5  8 0 0 0 0 2 2 0
     1  9  7  9 0 0 0 0 3 2 0
     4  9  7  9 0 0 0 0 2 5 0
     6  9 37  9 0 0 0 0 2 5 0
    10  9  8  9 0 0 0 0 3 1 0
    11  9 13  9 0 0 0 0 2 2 0
    12  9 12  9 0 0 0 0 2 1 0
    13  9 32  9 0 0 0 0 3 3 0
    15  9  8  9 0 0 0 0 2 2 0
     1 10 15 10 0 0 0 0 3 2 0
     4 10 11 10 0 0 0 0 2 5 0
     5 10 12 10 0 0 0 0 3 4 0
     6 10 28 10 0 0 0 0 2 5 0
    11 10  3 10 0 0 0 0 2 2 0
    12 10 15 10 0 0 0 0 2 1 0
    13 10 14 10 0 0 0 0 3 3 0
     1 11 15 11 0 0 0 0 3 2 0
     5 11 10 11 0 0 0 0 3 4 0
    10 11 11 11 0 0 0 0 3 1 0
    12 11 13 11 0 0 0 0 2 1 0
    13 11 21 11 0 0 0 0 3 3 0
    15 11  9 11 0 0 0 0 2 2 0
     5 12 11 12 0 0 0 0 3 4 0
     6 12  7 12 0 0 0 0 2 5 0
    10 12  8 12 0 0 0 0 3 1 0
    11 12 15 12 0 0 0 0 2 2 0
    12 12 16 12 0 0 0 0 2 1 0
    13 12 17 12 0 0 0 0 3 3 0
    15 12 11 12 0 0 0 0 2 2 0
     4 13  7 13 0 0 0 0 2 5 0
    10 13  7 13 0 0 0 0 3 1 0
    11 13 17 13 0 0 0 0 2 2 0
    12 13 35 13 0 0 0 0 2 1 0
    13 13 25 13 0 0 0 0 3 3 0
    15 13 14 13 0 0 0 0 2 2 0
     1 14 14 14 0 0 0 0 3 2 0
     4 14 12 14 0 0 0 0 2 5 0
     5 14 16 14 0 0 0 0 3 4 0
     6 14 20 14 0 0 0 0 2 5 0
     8 14  9 14 0 0 0 0 2 2 0
    11 14 15 14 0 0 0 0 2 2 0
    12 14 14 14 0 0 0 0 2 1 0
    13 14 31 14 0 0 0 0 3 3 0
    15 14 10 14 0 0 0 0 2 2 0
     1 15 10 15 0 0 0 0 3 2 0
     3 15  6 15 0 0 0 0 2 1 0
    Click image for larger version

Name:	KAR_piecewise.png
Views:	1
Size:	294.1 KB
ID:	1769680

  • #2
    You've posted several questions about these data.

    The outcome variable is clearly counted with (in practice) no zeros visible but the graph presumably features a great deal of overplotting.

    That's not a set-up in which I would expect piecewise linear fits to be especially helpful, if at all. Previous posts have exposed a risk of predicting meaningless negative counts.

    Although it's fashionable to model the effects of interventions as if they caused jumps in level and slope, a sceptical alternative to that is to check for smooth approximately exponential trends. Your data, or least your graph, indicates that the level of the outcome was declining within the pre-intervention phase.

    Comment


    • #3
      Nick Cox Hi Nick. yes, I have posted previously about these data, but they were different questions. I'm not sure how that is relevant here.

      I see what you're saying about the linear fit not being appropriate. Is there anyway after I run the regression above, that I can model smooth approximately exponential trends? The fact is that there is a jump in level at each intervention point and a change in slope over time, that is important for me to capture through the regression. As context, I had originally used the user contributed stata ITSA command which gave me exponential trends. However, the underlying model did not suit my data and what I wanted to do, which is why I moved to the piecewise regression.

      Comment


      • #4
        I doubt that I am the best person around to advise further. There is, or should be, literature on and methodology for handling counted responses for this kind of set-up. but I don't have any references.

        Comment

        Working...
        X