Announcement

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

  • Coefficient plots - using only values

    Dear all,

    I am writing to ask a question on the coefficient plots. As far as I know, Ben Jann has made a great a package on making coefficient plot from a regression model. Attached below is an example of the graph from Ben's -coefplot-.

    My problem is slightly different.

    I have a list of variables that have information only on the values of coefficients, standard errors, t-statistics, p-value, lower IC and upper IC. Because we were running regressions from a restricted computer. This might be particularly common in social sciences.

    b se t pvalue ll ul
    var1 0.001313 0.001097 1.197154 0.236892 -0.00089 0.003516

    Is there any way to plot a similar graph just using these values?

    Thank you very much and I look forward to hearing from you!

    Best regards,
    Long Hong

    Graph.png

  • #2
    Here's an example to get you started. The code uses the command labmask that is part of the labutil package written by Nick Cox and available on SSC.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 varname float(b se t pvalue ll ul)
    "mpg"    -186.84166  88.17601 -2.1189625 .03769533   -362.748 -10.93533
    "trunk"   -12.72642 104.87854 -.12134439   .903771  -221.9534 196.50053
    "length"   54.55294  35.56248  1.5340027 .12960176  -16.39227 125.49815
    "turn"   -200.32475 140.01657 -1.4307218 .15702333 -479.65015  79.00066
    "_cons"    8009.893  6205.538   1.290765 .20109335  -4369.817   20389.6
    end
    Code:
    *sort b  //you can use sort here if you want to change the order of coef on the graph
    gen order=_n
    drop if varname=="_cons"  // ignore if you want to include the constant 
    labmask order, values(varname)
    gr twoway rcap ll ul order, horiz || ///
        scatter order b , ///
        xline(0) ylab(,valuelabel angle(horizontal)) ///
        ytitle("") legend(off)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Thank you Carole J. Wilson! That is of great help!

      Comment


      • #4
        You can also create a matrix from the variables and then use coefplot:
        Code:
        clear
        input str6 varname float(b se t pvalue ll ul)
        "mpg"    -186.84166  88.17601 -2.1189625 .03769533   -362.748 -10.93533
        "trunk"   -12.72642 104.87854 -.12134439   .903771  -221.9534 196.50053
        "length"   54.55294  35.56248  1.5340027 .12960176  -16.39227 125.49815
        "turn"   -200.32475 140.01657 -1.4307218 .15702333 -479.65015  79.00066
        "_cons"    8009.893  6205.538   1.290765 .20109335  -4369.817   20389.6
        end
        
        // make matrix from data
        mkmat b se t pvalue ll ul, rownames(varname) matrix(R)
        
        // transpose matrix (just for convenience; reduces the required amount of
        //     typing in coefplot)
        matrix R = R'
        
        // Example 1:
        //     matrix(R): take coefficients from row 1 of matrix R
        //     se(2): take standard errors from row 2
        coefplot matrix(R), drop(_cons) se(2)
        
        // Example 2:
        //     ci((5 6)): take lower and upper bounds of CI from rows 5 and 6
        coefplot matrix(R), drop(_cons) ci((5 6))
        See http://repec.sowi.unibe.ch/stata/coe...arted.html#h-6 on using coefplot with matrices.
        ben

        Comment


        • #5
          Hi, Ben, It seems to me that something went wrong with your code.
          Code:
          . // Example 1:
          . //     matrix(R): take coefficients from row 1 of matrix R
          . //     se(2): take standard errors from row 2
          . coefplot matrix(R), drop(_cons) se(2)
          R: invalid syntax in se()
          r(198);
          Can you have a look?
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            Are you using and older version of coefplot? Try
            Code:
            adoupdate coefplot

            Comment


            • #7
              Dear Ben Jam, thank you very much for your help! It seems that River Huang is correct since the same error also happened from my side too. I have also followed Bjarte Aagnes 's suggestion and the same issue remains.

              Comment


              • #8
                The example code in #4 runs without error using updated Stata 15.1 and coefplot.ado version 1.8.1 18sep2017 :
                Code:
                .
                . version
                version 15.1
                
                .
                . update q
                (contacting http://www.stata.com)
                
                Update status
                    Last check for updates:  28 Aug 2018
                    New update available:    none         (as of 28 Aug 2018)
                    Current update level:    07 Aug 2018  (what's new)
                
                Possible actions
                
                    Do nothing; all files are up to date.
                
                .
                . adoupdate coefplot , dir(SITE)
                (note: adoupdate updates community-contributed files; type -update- to check for updates to official Stata)
                
                Checking status of specified packages...
                
                   [37] coefplot at http://fmwww.bc.edu/repec/bocode/c:
                        installed package is up to date
                
                (no packages require updating)
                
                .
                . which coefplot
                S:\Prog64\STATA\Stata15MP\ado\site\c\coefplot.ado
                *! version 1.8.1  18sep2017  Ben Jann
                
                .
                . clear
                
                . input str6 varname float(b se t pvalue ll ul)
                
                       varname          b         se          t     pvalue         ll         ul
                  1. "mpg"    -186.84166  88.17601 -2.1189625 .03769533   -362.748 -10.93533
                  2. "trunk"   -12.72642 104.87854 -.12134439   .903771  -221.9534 196.50053
                  3. "length"   54.55294  35.56248  1.5340027 .12960176  -16.39227 125.49815
                  4. "turn"   -200.32475 140.01657 -1.4307218 .15702333 -479.65015  79.00066
                  5. "_cons"    8009.893  6205.538   1.290765 .20109335  -4369.817   20389.6
                  6. end
                
                .
                . // make matrix from data
                . mkmat b se t pvalue ll ul, rownames(varname) matrix(R)
                
                .
                . // transpose matrix (just for convenience; reduces the required amount of
                . //     typing in coefplot)
                . matrix R = R'
                
                .
                . // Example 1:
                . //     matrix(R): take coefficients from row 1 of matrix R
                . //     se(2): take standard errors from row 2
                . coefplot matrix(R), drop(_cons) se(2)
                
                .
                . // Example 2:
                . //     ci((5 6)): take lower and upper bounds of CI from rows 5 and 6
                . coefplot matrix(R), drop(_cons) ci((5 6))
                
                .
                end of do-file
                Last edited by Bjarte Aagnes; 28 Aug 2018, 11:05.

                Comment


                • #9
                  Dear Bjarte, After updating -coefplot-, it works now. Thanks a lot.
                  Ho-Chuan (River) Huang
                  Stata 17.0, MP(4)

                  Comment

                  Working...
                  X