Announcement

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

  • Xtreg, illustrate regression in graph?

    Friends,

    I have a panel data set, looking like:

    Units Variable Year
    Unit 1 5 2000
    Unit 1 2 2001
    Unit 2 7 2000
    Unit 2 3 2001

    with 200 unique "units", and 20 years.

    I want to illustrate the value of "variable" over time. Xtline produces 200 lines, which is unreadable. twoway lfit/qfit produces a solid average (one line), however I want to use the Fixed effect estimated regression line. Is there any neat way of doing this? I appriciate specific code suggestions, thank you very much. / Joakim

  • #2
    Joakim:
    welcome to this forum.
    Do you mean something along the lines of the following toy-example?
    Code:
    . use "http://www.stata-press.com/data/r15/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtreg ln_wage age, fe
    
    Fixed-effects (within) regression               Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           Obs per group:
         within  = 0.1026                                         min =          1
         between = 0.0877                                         avg =        6.1
         overall = 0.0774                                         max =         15
    
                                                    F(1,23799)        =    2720.20
    corr(u_i, Xb)  = 0.0314                         Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0181349   .0003477    52.16   0.000     .0174534    .0188164
           _cons |   1.148214   .0102579   111.93   0.000     1.128107     1.16832
    -------------+----------------------------------------------------------------
         sigma_u |  .40635023
         sigma_e |  .30349389
             rho |  .64192015   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(4709, 23799) = 8.81                 Prob > F = 0.0000
    
    . predict Fixed_effect, u
    (24 missing values generated)
    
    . twoway (scatter Fixed_effect year)
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Carlo:

      Thank you very much for a quick respons. After trying derivations of your code I think I managed to get closer to what I want.

      So to be more clear: I would like to get an average regression line, like the results from an xtline ln_wage age (by group/unit- one line per group) but combined to one single line in a graph.

      I think in your example, I'm looking for something like:
      . xtreg ln_wage age, fe r
      . predict Fixed_effect
      .twoway line Fixed_effect age

      It seems to me this gives an illustration of the FE-regression. Does this seem reasonable to you? Best regards/ Joakim

      Comment


      • #4
        Joakim:
        it may well be reasonabale, conditional on your research goal.
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment

        Working...
        X