Announcement

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

  • Coefficient plot figure with omitted categories using non factorial variables in regression

    Hi everyone,

    Let's say I have 9 continuous variables that count the number of days per year with an average temperature in a given range. The bins are: <21, 21-23, 23-25, 25-27, 27-29, 29-31, 31-33, 33-35, >35
    The sum of all bins should be always equal to 365 days.

    Now, I am running the following regression:

    reg Y max_b1 max_b2 max_b3 max_b6 max_b7 max_b8 max_b9

    Therefore, the interpretation of max_b9 would be the effect of replacing a day from the reference category (i.e., [25-29]) for a day above 35.

    I want to create a coefficient plot that includes the reference category with the label [25-29] as the reference category and includes a dot right in zero, as the interpretation.

    So I run the regression and then use mata

    reg Y max_b1 max_b2 max_b3 max_b6 max_b7 max_b8 max_b9

    mat r= r(table)
    mat R1= r[1..6,1..3]
    matrix R2 = J(6, 1, .)
    matrix R2[1,1] = 0
    mat R3= r[1..6,4..7]
    matrix R = R1, R2, R3

    coefplot matrix(R), levels(99 95 90) vertical

    However, I get this error: "(R: could not determine CI1)"

    Anoyone knows how can I fix this ?

    Thanks !




  • #2
    coefplot is from SSC (FAQ Advice #12). A few issues with your post:

    1. Why generate the indicators by hand? Have a categorical variable and then use factor variable notation.

    Code:
    regress Y ib4.max
    In this way, you avoid coding errors such as omitting the "max_b5" indicator in #1. See

    Code:
    help fvvarlist
    2. Stata stores the estimates post regression in e(). Why extract the r(table) matrix in this case?

    3. No data example is included. Your issue can be fixed in the presence of one. See FAQ Advice #12 for details.

    4. You can only specify one confidence level in coefplot as far as I know. Not sure why you want to include three.

    Comment


    • #3
      Hi Andrew,

      Thanks for your reply. Let me clarify some of your points..

      The factor variable notation is not possible since I have a dataset which looks something like this:
      municipality year Y max_b1 max_b2 max_b3 max_b4 max_b5 max_b6 max_b7 max_b8 max_b9
      1001 2000 300 10 25 15 50 100 80 60 15 5
      1001 2001 100 15 15 10 20 80 100 50 55 15
      1001 2002 200 5 25 20 50 100 80 60 15 5
      1002 2000 100 10 15 15 50 90 90 70 15 5
      1002 2001 300 5 25 20 60 100 80 50 15 5
      1002 2002 50 10 10 45 40 85 60 90 15 5
      1003 2001 100 5 15 40 50 100 70 60 15 5
      1003 2002 100 10 15 15 40 100 80 50 45 5
      1003 2003 40 5 30 20 30 100 50 60 30 35

      Let's say I want to estimate a simple model

      reg Y max_b1 max_b2 max_b3 max_b6 max_b7 max_b8 max_b9

      So here the reference category is ref=max_b4 + max_b5

      I want to add to the coefficient plot below a category named [25,29] that shows a point estimate in zero right between [23,25] and [29,31]

      Thanks !


      Click image for larger version

Name:	Graph.png
Views:	1
Size:	108.1 KB
ID:	1751060


      Comment


      • #4
        See a similar question at https://www.statalist.org/forums/for...-with-coefplot.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input int(municipality year y) byte(max_b1 max_b2 max_b3 max_b4 max_b5 max_b6 max_b7 max_b8 max_b9)
        1001 2000 300 10 25 15 50 100  80 60 15  5
        1001 2001 100 15 15 10 20  80 100 50 55 15
        1001 2002 200  5 25 20 50 100  80 60 15  5
        1002 2000 100 10 15 15 50  90  90 70 15  5
        1002 2001 300  5 25 20 60 100  80 50 15  5
        1002 2002  50 10 10 45 40  85  60 90 15  5
        1003 2001 100  5 15 40 50 100  70 60 15  5
        1003 2002 100 10 15 15 40 100  80 50 45  5
        1003 2003  40  5 30 20 30 100  50 60 30 35
        end
        
        gen zero=0
        reg y max_b1 max_b2 max_b3 zero max_b6 max_b7 max_b8 max_b9
        coefplot, vert drop(_cons) omitted xlab(1 "<21" 2 "[21-23]" 3 "[23-25]" 4 "[25-29]" 5  "[29-31]" 6 "[31-33]" 7 "[33-35]" 8 ">35")
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.5 KB
ID:	1751071

        Comment

        Working...
        X