Announcement

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

  • How to show a missing year (which has no estimate) on the abscissa axis of a coefplot?


    Hello to everyone,

    I have a dataset with several years of data. I am doing an event study on this dataset. For one year (due to COVID-19), I have no data. Although this year is not included in the estimation (and therefore has no coefficient), I would like to show it on the abscissa scale of my coefplot.

    With the code below I want to make year 9 appear on the abscissa axis between years 8 (the reference year) and 10.

    Does anyone have an idea?
    Thank you in advance!

    Code:
    clear 
    set obs 10000
    egen id = seq(), from(1) to(10000) block(1)
    gen year=1 if id<=1000
    replace year=2 if year==. & id<=2000
    replace year=3 if year==. & id<=3000
    replace year=4 if year==. & id<=4000
    replace year=5 if year==. & id<=5000
    replace year=6 if year==. & id<=6000
    replace year=7 if year==. & id<=7000
    replace year=8 if year==. & id<=8000
    replace year=10 if year==. & id<=9000
    replace year=11 if year==.
    gen score = 1 + rnormal()
    
    reg score ib8.year
    
    coefplot, keep(*.year) vertical  base mcolor()  lpattern(dash) color(black) yline(0,lcolor() lpattern(dash))  xline(8)

  • #2
    Hey Leo,

    the following code should work. I requires some matrix wrangling, though.

    Code:
    clear
    set obs 10000
    egen id = seq(), from(1) to(10000) block(1)
    gen year=1 if id<=1000
    replace year=2 if year==. & id<=2000
    replace year=3 if year==. & id<=3000
    replace year=4 if year==. & id<=4000
    replace year=5 if year==. & id<=5000
    replace year=6 if year==. & id<=6000
    replace year=7 if year==. & id<=7000
    replace year=8 if year==. & id<=8000
    replace year=10 if year==. & id<=9000
    replace year=11 if year==.
    gen score = 1 + rnormal()
    
    reg score ib8.year
    
    * Store results as matrix
    matrix B = r(table)
    
    * Create "empty" matrix for year==9
    matrix A = (0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0)
    matrix colnames A = 9.year
    
    * Subset result marix to add empty matrix at the right point
    matrix B1 = B[1..9, 1..8]
    matrix B2 = B[1..9,9..11]
    
    * Combine all three matrices
    matrix C = B1,A,B2
    
    * Plot
    coefplot matrix(C) , keep(*.year) vertical  base mcolor()  lpattern(dash) color(black) yline(0,lcolor() lpattern(dash))  xline(8) se(2) xscale(range(1 11)) xlabel(1(1)11)
    Best
    Sebastian

    Comment


    • #3
      Hey Sebastian,
      It works perfectly!
      Thank you

      Comment

      Working...
      X