Announcement

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

  • storing the beta coefficients for coefplot?

    Hi there,

    I'd like to depict the standardized beta coefficients in a coefplot but don't know how...

    This is the code I am using:

    Code:
    regress studentsat totalincome teachingincome researchincome teachingstudentfte i.department i.region, beta
     
     estimates store m1
     
     coefplot m1, ///
        plotlabels("Model 1" ) ///
        title("Regression Coeffients Modelling Points")  ///
        graphregion(fcolor(white))
    Thanks in advance!!

  • #2
    If you install esttab (SSC), it stores a matrix of the beta coefficients which you may use.

    Comment


    • #3
      Hi Andrew,

      thanks for your quick response !
      How do I depict them in the coefplot though ?

      Comment


      • #4
        Code:
        sysuse auto, clear
        regress  price mpg weight i.rep78, beta
        qui esttab, beta
        mat beta= e(beta)
        coefplot mat(beta), drop(_cons) scheme(s1mono)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	115.7 KB
ID:	1540490

        Comment


        • #5
          Hi Andrew,

          Thanks a lot!

          Guest
          Last edited by sladmin; 06 Jul 2023, 10:54. Reason: anonymize original poster

          Comment


          • #6
            Hi Andrew, this was really helpful... I was wondering though, how do you get the confidence intervals? I've tried with data of my own and it's not worked because I'm using factor variables. How would you do it in the example you have here? Thank you in advance!

            Comment


            • #7
              See #5 https://www.statalist.org/forums/for...s-for-coefplot

              Comment


              • #8
                Hi Andrew, thanks for sharing and for such a quick reply, but I was interested in how to do it by keeping the same format to have factor coefficients displayed, not having the coefficients by factor displayed.

                I essentially am curious about what to add to this:
                reg avg_delay ib1.treat_delayexp ib2.polval_recode, beta
                qui esttab, beta
                mat beta= e(beta)
                coefplot mat(beta), drop(_cons) xline(0) pstyle(p2) title("Delay Exp. Standardized Coefficents: avg_delay")
                Which gives me this:
                Click image for larger version

Name:	plot1.png
Views:	1
Size:	125.0 KB
ID:	1615433




                But I'm looking to add CIs like this but for the standardized:
                reg avg_delay ib1.treat_delayexp ib2.polval_recode, beta
                estimates store D
                coefplot (D, label("Delay Exp.") pstyle(p2)), drop(_cons) xline(0) title("Delay Exp. Non-std Coefs w/ 95% CI: avg_delay", size(medium)) xtitle(Non-standardized Coefficent Estimates)
                Click image for larger version

Name:	Screen Shot 2021-06-19 at 1.55.52 PM.png
Views:	1
Size:	135.7 KB
ID:	1615434





                The issue arises when I try and calculate the CIs with the factor variables...

                With regard to the code in your example you shared in the other thread (which, as I mentioned is not how I would like to represent the data) I had a few issues:

                Firstly, what is disp? I figure it's the display command, but I can't seem to get it to work and couldn't figure out if I needed to install something (a bit new to all this, my apologies if this is basic)

                Ignoring the disp and doing things not in a loop (To make it shorter for the purposes of demonstration I removed one of the factor variables):
                preserve

                qui sum avg_delay
                replace avg_delay= (avg_delay- r(mean))/r(sd)

                qui sum i1.polval_recode
                replace i1.polval_recode= (i1.polval_recode- r(mean))/r(sd)

                qui sum i2.polval_recode
                replace i2.polval_recode= (i2.polval_recode- r(mean))/r(sd)

                qui sum i3.polval_recode
                replace i3.polval_recode= (i3.polval_recode- r(mean))/r(sd)

                eststo all: regress avg_delay ib2.polval_recode, nocons

                restore

                coefplot all, scheme(s1color)
                For the factor variables, I get the error 'factor-variable and time-series operators not allowed'
                (This is what I referenced when I mentioned in my reply that it's not working)


                Thank you kindly for your help
                -Nick
                Last edited by Nick Hadjimichael; 19 Jun 2021, 16:14.

                Comment


                • #9
                  Firstly, what is disp? I figure it's the display command, but I can't seem to get it to work and couldn't figure out if I needed to install something (a bit new to all this, my apologies if this is basic)
                  disp is the variable "displacement" in the auto dataset. I have variable abbreviation set on which allows me to abbreviate variables.

                  For the factor variables, I get the error 'factor-variable and time-series operators not allowed'
                  (This is what I referenced when I mentioned in my reply that it's not working)
                  You need to create the indicators by hand if you are using the method that I suggest in the linked thread. Use tab with the -gen- option. Stata generates variable labels to identify the created indicators, but better to relabel them eventually. Here is an illustration using the example in #4.

                  Code:
                  sysuse auto, clear
                  *Without CIs
                  regress  price mpg weight i.rep78, beta
                  qui esttab, beta
                  mat beta= e(beta)
                  set scheme s1color
                  coefplot mat(beta), drop(_cons) title("Coefplot without CIs") saving(gr1, replace)
                  
                  *With CIs
                  tab rep78, gen(repair)
                  foreach var of varlist price mpg weight repair2-repair5{
                      qui sum `var'
                      replace `var'= (`var'- r(mean))/r(sd)
                  }
                  levelsof rep78, local(labrep78)
                  foreach level of local labrep78{
                      lab var repair`level' "Repair Record 1978 = `level'"
                  }
                   
                  eststo m1: regress price mpg weight repair2-repair5, nocons
                  coefplot m1, nokey title("Coefplot with CIs") saving(gr2, replace)
                  gr combine gr1.gph gr2.gph
                  Click image for larger version

Name:	Graph.png
Views:	1
Size:	65.0 KB
ID:	1615436

                  Comment


                  • #10
                    Thank you so much for your help!

                    Comment

                    Working...
                    X