Announcement

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

  • Plotting regression coefficients as a histogram

    Hello,

    I have to run about 35 regressions and plot the estimates of the key regression coefficient on a histogram. Do you know how to do this?

    I have started experimenting with the sample data provided below but I could not manage to plot the estimates of the key regression coefficient mpg on a histogram. First I thought that coefplot may be appropriate, but then I realised that it cannot nicely visualise so many estimates and somehow the data should be plotted as a histogram.



    sysuse auto, clear

    regress price mpg trunk length turn if foreign==0
    estimates store ELF1

    regress price mpg trunk length turn if for==1
    estimates store ELF2

    regress price mpg trunk length if for==1
    estimates store ELF3

    regress price mpg trunk length turn if foreign==0
    estimates store ELF4

    regress price mpg trunk length turn if foreign==0
    estimates store ELF5

    regress price mpg trunk length turn if for==1
    estimates store ELF6

    regress price mpg trunk length turn if foreign==0
    estimates store ELF7

    regress price mpg trunk length turn if for==1
    estimates store ELF8

    regress price mpg trunk length turn if foreign==0
    estimates store ELF9

    regress price mpg trunk length turn if for==1
    estimates store ELF10

    regress price mpg trunk length turn if foreign==0
    estimates store ELF11

    regress price mpg trunk length turn if for==1
    estimates store ELF12

    regress price mpg trunk length turn if foreign==0
    estimates store ELF13

    regress price mpg trunk length turn if for==1
    estimates store ELF14

    regress price mpg trunk length turn if foreign==0
    estimates store ELF15

    regress price mpg trunk length turn if for==1
    estimates store ELF16

    regress price mpg trunk length turn if foreign==0
    estimates store ELF17

    regress price mpg trunk length turn if for==1
    estimates store ELF18

    coefplot ELF1 ELF2 ELF3 ELF4 ELF5 ELF6 ELF7 ELF8 ELF9 ELF10 ELF11 ELF12 ELF13 ELF14 ELF15 ELF16 , xline(0) keep(mpg) drop(_cons)


  • #2
    If your real problem is regression for the same response and predictors for subsets of the data, statsby is one way of producing a results set from which a histogram is immediate.

    Comment


    • #3
      Thank you, Nick, this works for me.
      Last edited by Iva Mihaylova; 01 Apr 2021, 15:56.

      Comment


      • #4
        OK. The principle behind statsby is still one that you might well aim at. That is, put your estimates into variables because for histograms you need variables!

        As I'm imagining that people have often wanted to do this, but also thinking that I can't at this moment recall a canned way to do it. I am going to watch to see if someone else can identify a wheel already invented/

        Comment

        Working...
        X