Announcement

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

  • Adding Significance Stars to a Coefplot generated with Matrices

    Dear Stata Forum,
    I am currently trying to add significance stars to a graph I generate via coefplot using matrices.

    The Code I use is the following:

    Code:
    quietly regress coutcome1 i.treatment##i.interaction  ///
                    ${controls} , robust
                    
                    lincom 1.treatment
                    local b = r(estimate)*100
                    local se = r(se)
                    local pvalue = r(p)
                    local t = r(t)
                    local ll95 = r(lb)*100
                    local ul95 = r(ub)*100
                    local df = r(df)
                    
                    mat model1[1,5] = `b' \  `se'  \ `t' \ `pvalue' \  `ll95' \ `ul95' \ `df'    
                    matrix colnames model1 = (1) (2) (3) (4) (5)
                    matrix rownames model1 = b se t pvalue ll95 ul95 df
    
                    lincom 1.treatment + 1.treatment#1.interaction
                    local b = r(estimate)*100
                    local se = r(se)
                    local pvalue = r(p)
                    local t = r(t)
                    local ll95 = r(lb)*100
                    local ul95 = r(ub)*100
                    local df = r(df)
    
                    mat model2[1,1] = `b' \  `se'  \ `t' \ `pvalue' \  `ll95' \ `ul95' \ `df'                
                    matrix colnames model2 = (1)
                    matrix rownames model2 = b se t pvalue ll95 ul95 df
    
    [Repeat for more outcomes]
    
    quietly regress coutcome5 i.treatment##i.interaction  ///
                    ${controls} , robust
                    
                    lincom 1.treatment
                    local b = r(estimate)*100
                    local se = r(se)
                    local pvalue = r(p)
                    local t = r(t)
                    local ll95 = r(lb)*100
                    local ul95 = r(ub)*100
                    local df = r(df)
                    
                    mat model1[1,5] = `b' \  `se'  \ `t' \ `pvalue' \  `ll95' \ `ul95' \ `df'    
                    matrix colnames model1 = (1) (2) (3) (4) (5)
                    matrix rownames model1 = b se t pvalue ll95 ul95 df
    
                    lincom 1.treatment + 1.treatment#1.interaction
                    local b = r(estimate)*100
                    local se = r(se)
                    local pvalue = r(p)
                    local t = r(t)
                    local ll95 = r(lb)*100
                    local ul95 = r(ub)*100
                    local df = r(df)
                    
                    mat model2[1,5] = `b' \  `se'  \ `t' \ `pvalue' \  `ll95' \ `ul95' \ `df'                    
                    matrix colnames model2 = (1) (2) (3) (4) (5)
                    matrix rownames model2 = b se t pvalue ll95 ul95 df
    
    
    
    coefplot (matrix(model1), keep ( (1) (2) (3) (4) (5) ) ci((5 6)) mlabel(cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.10, "*", ""))))   )  ///
                (matrix(model2), keep ( (1) (2) (3) (4) (5) ) ci((5 6)) mlabel(cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.10, "*", ""))))   ), ///
                    title( "Treatment Effect in Percentage Points" , size(large))
    The reason I use this approach is that I want to have the main treatment effect represented close to its interaction effect, so that readers can compare the two at one glance. Quite similar to the standard comparison of two models using coefplot
    see: http://repec.sowi.unibe.ch/stata/coe...ted/plots1.pdf

    Yet, when I try to add significance stars dependent on the p-values this approach crashes. I have the feeling that I have to access r(table) to add my coefficient results and trick coefplot into thinking that my matrices are regression outcomes.
    Still, I do not know how to do that.
    Can anybody please help?

    All the best,
    Fabian
    Last edited by Fabian Mierisch; 12 Dec 2022, 02:32.

  • #2
    How does the formation of the matrix1 work?
    Last edited by George Ford; 13 Dec 2022, 07:50.

    Comment


    • #3
      Code:
      clear all
      use auto, clear
      
      matrix model1 = J(7,2,.)
      
      reg price weight length foreign
      lincom foreign
      return list
      matrix model1[1,1] = r(estimate) \ r(se) \ r(t) \ r(p) \ r(lb) \ r(ub) \ r(df)
      matrix colnames model1 = (1) (2)
      matrix rownames model1 = b se t pval ll95 ul95 df
      
      reg price weight mpg foreign
      lincom foreign
      return list
      matrix model1[1,2] = r(estimate) \ r(se) \ r(t) \ r(p) \ r(lb) \ r(ub) \ r(df)
      
      coefplot matrix(model1), aux(4) ci((5 6))  mlabel(cond(@aux1<.001, "***", cond(@aux1<.01, "**", cond(@aux1<.05, "*", "")))) mlabposition(12) mlabsize(vsmall)

      Comment


      • #4
        Dear Mr. Ford,

        Thank you very much! This works perfectly.
        Also, I looked into the "aux" option and think it has the potential to solve many more issues I sometimes have with coefplot.

        Kind regards,
        Fabian
        Last edited by Fabian Mierisch; 15 Dec 2022, 10:53.

        Comment

        Working...
        X