Announcement

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

  • Plot coefficient over years

    I would like to run the same regression each year and then plot the coefficients with years on the x-axis and beta on the y-axis.

    Here is an MWE. Any suggestions

    Code:
    clear all
    input year y x
    2001 1 1
    2001 2 0
    2001 2 0
    2002 1 1
    2002 3 0
    2002 2 1
    2003 1 1
    2003 3 0
    2003 5 1
    2004 6 0
    2004 2 1
    2004 1 1
    2004 4 0
    2004 1 0
    2005 1 1
    2005 2 1
    2005 3 0
    2005 1 0
    end
    
    levelsof year, local(levels)
    foreach y in `levels' {
        reg y x if year == `y'
    }

  • #2
    See
    Code:
    help statsby
    With your example data:
    Code:
    . use ~/Downloads/example
    
    . statsby _b, by(year) : regress y x
    (running regress on estimation sample)
    
          Command: regress y x
               By: year
    
    Statsby groups
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
    .....
    
    . list
    
         +-----------------------------+
         | year        _b_x    _b_cons |
         |-----------------------------|
      1. | 2001          -1          2 |
      2. | 2002        -1.5          3 |
      3. | 2003           0          3 |
      4. | 2004   -2.166667   3.666667 |
      5. | 2005         -.5          2 |
         +-----------------------------+
    
    .

    Comment


    • #3
      Thank you

      Comment

      Working...
      X