Announcement

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

  • Two-Way Coefplot

    I am running 40 regressions. In each regression I regress an indicator for having price at least as great as a certain value (e.g. 0, 2500, 5000, 7500,..., 100000) on one variable of interest. Now I would like to plot the 40 coefficients from each regression in the same graph, have the price as the X-axis, and each coefficient with the 95% confidence interval should be exactly above the price for which the indicator is used as the outcome variable. So the coefficient with the 95% confidence interval from a regression of having price at least as great as 0 should be above 0, the coefficient with the 95% confidence interval from a regression of having price at least as great as 2500 should be above 2500 and so on. I have tried coefplot but I can't add a continuous X-axis. However I definitely need a continuous X-Axis because I want to add vertical lines at certain price levels and I want to control how many labels will be on the X-axis. Here is an example for the first six regressions how the graph should look like.


    Click image for larger version

Name:	example.png
Views:	1
Size:	41.3 KB
ID:	1634280


    Here is a simple code how I run the regressions using the auto data set:

    Code:
    sysuse auto
    
    foreach n of numlist 3000 3500 4000 4500 5000 5500 6000 6500 7000 {
        gen price_`n'=(price>`n')    
    }
    
    foreach dv in price_3000 price_3500 price_4000 price_4500 price_5000 price_5500 price_6000 price_6500 price_7000 {
        eststo `dv': reg `dv' weight
    }

  • #2
    Trevor, I have a clumsy solution as below (graph not well formatted). There will be easier ways.

    Code:
    gen b = .
    gen cil = .
    gen ciu = .
    gen x = .
    local j = 1
    
    forvalues i = 3000(500)7000 {
        gen price_d = price >= `i'
        reg price_d weight
        replace x = `i' in `j'
        replace b = _b[weight] in `j'
        replace cil = r(table)[5,1] in `j'
        replace ciu = r(table)[6,1] in `j'
        drop price_d
        local ++j
    }
    
    scatter b x || rcap cil ciu x

    Comment

    Working...
    X