Announcement

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

  • Plotting Coefficients and Varying Coefficient Model

    Hi

    I am currently estimating the relationship between happiness and age using panel data with fixed effect.
    Assuming my model is " happy age male child i.marital birthyear, fe "

    Question 1:
    I would like to replicate the method of Clark (2007) "Born To Be Mild? Cohort Effects Don’t (Fully) Explain Why Well-Being Is U-Shaped in Age" (http://ftp.iza.org/dp3170.pdf)

    I was wondering if there is a command for STATA to plot the coefficient of each variables to see the trend. In the picture attached, coefficients of each age dummy variable has been plot to see the U-Shaped across each age group.

    I have tried this with the command marginsplot and coefplot and they don't seem to be able to replicate Clark (2007)'s graph.


    Question 2:

    I would like to try using Movshuk's (2011) semiparametric model with varying-coefficient. -> https://www.jstage.jst.go.jp/article...0/4_0_133/_pdf

    so the age variables will be a function of s(age), which is a nonparametric estimate of the overall age effect.

    However, I am quite confused about how this can be done as the article used R instead of STATA.

    From my understanding, to do so we need to use the command xtmixed????

    using the my model then the command should be

    " xtmixed happy age male child i.marital birthyear || _all: age" ????? Is this correct?

    or is it better to use the command XTNPTIMEVAR ? as it is a non-parametric time-varying coefficients panel data models with fixed effects

    I also have the same question with Question 1 that how can I plot the value of the age coefficient from this model to see the it's trend.

    Thank you so much in advance,
    Viola

  • #2
    Regarding Question 1: So we don't know what your data looks like, which makes it hard to give concrete advice. Keeping it somewhat general, I'll just assume that you have variables called happy (which is your outcome), age and birthyear, which are your predictors of interest, and some other variables that serve as covariates. The first of your attached graphs does not appear to be a plot of coefficients of indicator variables--it looks like a plot of predicted outcomes by age.

    So it will go something like this:

    Code:
    regress happy i.age // OTHER COVARIATES TOO
    margins age
    marginsplot
    Of course if you have longitudinal data on the same people, then -regress- is not suitable and you will have to go to some appropriate other model, etc.

    Now, you say you've tried -marginsplot- already and aren't getting what you expected. But perhaps your initial regression model was different, or you didn't use -margins- the right way. We are left in the dark trying to guess what you actually did. And all we know about what you got as a result is that it doesn't look like a particular graph you had in mind.

    So if you want more specific advice, you need to show us exactly what commands you have tried and how Stata responded. Be sure to do this by copying directly from the Results window or your Stata log file and pasting into a code block (see FAQ#12 if you are not familiar with code blocks) on the forum editor without any editing so that the what we see will be easily readable and will not deviate in some subtle but potentially critical way from what actually happened.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Regarding Question 1: So we don't know what your data looks like, which makes it hard to give concrete advice. Keeping it somewhat general, I'll just assume that you have variables called happy (which is your outcome), age and birthyear, which are your predictors of interest, and some other variables that serve as covariates. The first of your attached graphs does not appear to be a plot of coefficients of indicator variables--it looks like a plot of predicted outcomes by age.

      So it will go something like this:

      Code:
      regress happy i.age // OTHER COVARIATES TOO
      margins age
      marginsplot
      Of course if you have longitudinal data on the same people, then -regress- is not suitable and you will have to go to some appropriate other model, etc.

      Now, you say you've tried -marginsplot- already and aren't getting what you expected. But perhaps your initial regression model was different, or you didn't use -margins- the right way. We are left in the dark trying to guess what you actually did. And all we know about what you got as a result is that it doesn't look like a particular graph you had in mind.

      So if you want more specific advice, you need to show us exactly what commands you have tried and how Stata responded. Be sure to do this by copying directly from the Results window or your Stata log file and pasting into a code block (see FAQ#12 if you are not familiar with code blocks) on the forum editor without any editing so that the what we see will be easily readable and will not deviate in some subtle but potentially critical way from what actually happened.

      Dear Clyde


      Thank you so much for your reply. My apologies for the unclear information I have provided. My data is British Household Panel Survey , which contains the social demographic of an individual and also their self-reported life satisfaction. It is the same data used for Clark (2007)'s article that I am trying to replicate.

      I have tried this command before, but in the attached regression of Clark (2007)
      We can see that when we regress life satisfaction with each group, the coefficients of age 20-24 is -0.136 where age 15-19 is the omitted group.
      Therefore, it is show that X1 = Age 15-19 ; Y = 0
      X2 = Age 20-21; Y = -0.136

      Nevertheless, when I used the marginsplot command, the margin value is plot in the graph instead of the coefficient from the regression (which is what I want to be plotted).
      Both values has the same trend, but since I am replicating Clark (2007)'s method. I am curious how he obtain such graph.

      *Just to make it clear here that I did not worry that I did not get the same regression result as I am using the data with more waves.*


      Code:
       . regress lifesat i.agegrp
      
            Source |       SS           df       MS      Number of obs   =   183,346
      -------------+----------------------------------   F(16, 183329)   =    128.76
             Model |  950.306198        16  59.3941374   Prob > F        =    0.0000
          Residual |  84567.5684   183,329  .461288549   R-squared       =    0.0111
      -------------+----------------------------------   Adj R-squared   =    0.0110
             Total |  85517.8746   183,345  .466431452   Root MSE        =    .67918
      
      ------------------------------------------------------------------------------
           lifesat |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            agegrp |
        Age 20-24  |  -.0241347   .0082066    -2.94   0.003    -.0402195   -.0080499
        Age 25-29  |   .0172388   .0076096     2.27   0.023     .0023242    .0321535
        Age 30-34  |   .0526956   .0073467     7.17   0.000     .0382963    .0670948
        Age 35-39  |   .0005517   .0073618     0.07   0.940    -.0138772    .0149806
        Age 40-44  |  -.0780197   .0074482   -10.47   0.000    -.0926181   -.0634213
        Age 45-49  |  -.1046727   .0076098   -13.75   0.000    -.1195878   -.0897576
        Age 50-54  |  -.1049766   .0078356   -13.40   0.000    -.1203342   -.0896189
        Age 55-59  |  -.1027569   .0082311   -12.48   0.000    -.1188896   -.0866241
        Age 60-64  |  -.1324004   .0085193   -15.54   0.000     -.149098   -.1157029
        Age 65-69  |  -.1505923   .0089561   -16.81   0.000     -.168146   -.1330386
        Age 70-74  |  -.1644385   .0096316   -17.07   0.000    -.1833161   -.1455608
        Age 75-79  |  -.1782977   .0112694   -15.82   0.000    -.2003854   -.1562099
        Age 80-84  |  -.2095742   .0144447   -14.51   0.000    -.2378856   -.1812629
        Age 85-89  |  -.1761324   .0207115    -8.50   0.000    -.2167265   -.1355384
        Age 89-94  |  -.1782017   .0384865    -4.63   0.000    -.2536343   -.1027691
       Age 95-100  |   -.296794   .0796846    -3.72   0.000     -.452974    -.140614
                   |
             _cons |   3.269397   .0055332   590.87   0.000     3.258552    3.280242
      ------------------------------------------------------------------------------
      Code:
      . margins agegrp
      
      Adjusted predictions                            Number of obs     =    183,346
      Model VCE    : OLS
      
      Expression   : Linear prediction, predict()
      
      ------------------------------------------------------------------------------
                   |            Delta-method
                   |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            agegrp |
        Age 15-19  |   3.269397   .0055332   590.87   0.000     3.258552    3.280242
        Age 20-24  |   3.245262   .0060607   535.46   0.000     3.233383    3.257141
        Age 25-29  |   3.286636    .005224   629.14   0.000     3.276397    3.296874
        Age 30-34  |   3.322092    .004833   687.38   0.000      3.31262    3.331565
        Age 35-39  |   3.269948   .0048559   673.40   0.000     3.260431    3.279466
        Age 40-44  |   3.191377    .004986   640.06   0.000     3.181604     3.20115
        Age 45-49  |   3.164724   .0052243   605.77   0.000     3.154484    3.174964
        Age 50-54  |    3.16442   .0055481   570.36   0.000     3.153546    3.175294
        Age 55-59  |    3.16664   .0060938   519.65   0.000     3.154696    3.178584
        Age 60-64  |   3.136996   .0064778   484.27   0.000       3.1243    3.149693
        Age 65-69  |   3.118804   .0070424   442.86   0.000     3.105001    3.132607
        Age 70-74  |   3.104958   .0078836   393.85   0.000     3.089507     3.12041
        Age 75-79  |   3.091099   .0098175   314.86   0.000     3.071857    3.110341
        Age 80-84  |   3.059822    .013343   229.32   0.000     3.033671    3.085974
        Age 85-89  |   3.093264   .0199587   154.98   0.000     3.054146    3.132383
        Age 89-94  |   3.091195   .0380867    81.16   0.000     3.016546    3.165844
       Age 95-100  |   2.972603   .0794923    37.39   0.000       2.8168    3.128406
      ------------------------------------------------------------------------------
      Furthermore, do you have any advice on the varying-coefficient model command in Question 2?

      Thank you so much

      Viola
      Last edited by Viola Eye; 07 Mar 2016, 07:11.

      Comment


      • #4
        OK, sorry. I misunderstood your purpose. So you really do want to plot the coefficients themselves, which represent not the value of life satisfaction but the change in life satisfaction relative to age group 15-19. There is a user-written program -coefplot- that I believe does this kind of thing, but I have never used it myself. (I've never had occasion to plot coefficients in my work.) But you could do it yourself:

        Code:
        regress lifesat i.agegrp
        
        // CREATE A TEMPORARY FILE WITH COEFFICIENTS
        tempfile for_graph
        capture postutil clear
        postfile handle int agegrp float coef using `for_graph'
        
        forvalues i = 1/17 { // THERE ARE 17 AGE-GROUPS
            post handle (`i') (_b[`i'.agegrp])
        }
        postclose handle
        
        // RETAIN THE VALUE LABELS FOR agegrp
        tempfile for_label
        local agegrp_label: value label agegrp
        label save `agegrp_label' using `for_label'
        
        // NOW PLOT THE GRAPH
        use `for_graph', clear
        run `for_label'
        label values agegrp `agegrp_label'
        isid agegrp, sort
        graph twoway connect coef agegrp // CUSTOMIZE GRAPH WITH OPTIONS AS DESIRED
        Note: This code overwrites the data in memory. If you need to continue with additional analyses of the data, put -preserve- before the code that plots the graph, and -restore- after.

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          OK, sorry. I misunderstood your purpose. So you really do want to plot the coefficients themselves, which represent not the value of life satisfaction but the change in life satisfaction relative to age group 15-19. There is a user-written program -coefplot- that I believe does this kind of thing, but I have never used it myself. (I've never had occasion to plot coefficients in my work.) But you could do it yourself:

          Code:
          regress lifesat i.agegrp
          
          // CREATE A TEMPORARY FILE WITH COEFFICIENTS
          tempfile for_graph
          capture postutil clear
          postfile handle int agegrp float coef using `for_graph'
          
          forvalues i = 1/17 { // THERE ARE 17 AGE-GROUPS
          post handle (`i') (_b[`i'.agegrp])
          }
          postclose handle
          
          // RETAIN THE VALUE LABELS FOR agegrp
          tempfile for_label
          local agegrp_label: value label agegrp
          label save `agegrp_label' using `for_label'
          
          // NOW PLOT THE GRAPH
          use `for_graph', clear
          run `for_label'
          label values agegrp `agegrp_label'
          isid agegrp, sort
          graph twoway connect coef agegrp // CUSTOMIZE GRAPH WITH OPTIONS AS DESIRED
          Note: This code overwrites the data in memory. If you need to continue with additional analyses of the data, put -preserve- before the code that plots the graph, and -restore- after.

          Dear Clyde

          Thank you so much I have tried your command and it works!!
          I also tried the coefplot command as well, but it uses agegrp as a Y axis and coefficient as the X axis. I was wondering if there is a command that allow me to switch between X and Y axis?
          I have tried to look for it, but they only switch from left to right or up to down not exchanging the axis between each other that I actually want.

          Thank you so so much!
          Viola

          Comment


          • #6
            I also tried the coefplot command as well, but it uses agegrp as a Y axis and coefficient as the X axis. I was wondering if there is a command that allow me to switch between X and Y axis?
            Not that I know of. But in my own work I tend to use very simple and minimalist graphics--partly a question of what I do, and partly my taste. So there is a huge world of Stata graphics out there that I have never explored, or even heard about. Perhaps somebody else who is more involved in this end of things can chime in.

            Comment


            • #7
              This is an old thread but I was searching for the same topic/solution and found this and thought I'd share it for other who the same question.
              Look at example 3.5.8 for some ideas on how to produce -coefplot- graphs with the continuous var plotted on the x-axis, and also 3.5.6 for help plotting -xtmixed- components:

              ftp://ftp.repec.org/opt/ReDIF/RePEc/...3-coefplot.pdf
              Last edited by eric_a_booth; 19 Sep 2017, 09:02.
              Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

              Comment

              Working...
              X