Announcement

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

  • Graph the value of r2 over time

    Hey,

    I wonder if anyone knows how to make a graph that includes an association's r2value over time? I have a dataset that covers 20 years and would like to examine how much one variable explains the outcome of another variable, and how this has changed over the years. Does anyone know which command produces this?

    Best wishes

  • #2
    You don't give a data example (FAQ Advice #12) or even indicate your data structure or variable names.

    But here is an example intended to show some Stata technique rather than to exemplify good statistical practice.


    Code:
    . webuse grunfeld, clear
    
    
    . statsby rsq=e(r2) , by(year) : regress mvalue invest
    (running regress on estimation sample)
    
          Command: regress mvalue invest
              rsq: e(r2)
               By: year
    
    Statsby groups
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
    ....................
    
    . line rsq year
    
    .

    Comment


    • #3
      Nick's plan works.

      Or use asreg. It will give you the R2 as a variable, then plot that.

      Comment


      • #4
        Thank you so much, it worked at first. However, when I before the analysis make a simple recode on the dependent variable to get rid of missing values etc. I then get the error message "no; dataset in memory has changed since last saved" when trying to make statsby. Do you know why?

        recode oldvar(52/99=.), gen(newvar)
        preserve
        statsby rsq=e(r2) , by(year) : regress newvar i.gender
        line rsq year
        restore

        Comment


        • #5
          Perhaps the error message

          dataset in memory has changed since last saved
          means what it says. You don't give any information to the contrary. This could be (1) you opened the dataset (2) you created some new variables.

          Code:
          save
          the dataset or use the clear option in statsby if you don't care about saving your changes.

          Comment

          Working...
          X