Announcement

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

  • Graph mean values using statsby

    Hi,

    I'm trying to make a time series that shows the mean values on a variable by different groups over several years with confidence intervalls. I found a syntax in another thread but don't seem to make it work:
    Time variable: year
    Groups: gender (women/men)


    statsby mean=r(mean) ub=r(ub) lb=r(lb), by(gender year) : ci dependentvar

    When running this syntax I solely get the error message: "no; dataset in memory has changed since last saved"

    Does anyone know why?

  • #2
    There are two problems with your code.
    1. When running -statsby- you have to tell Stata what to do with the results. There are two choices: replace the existing data set, or save them to a file. For the former, you must add the -clear- option to -statsby-. For the latter you must add the -saving()- option with the filename. You specified neither.*
    2. -ci- by itself is not a valid command, at least not in recent versions of Stata. You must specify mean, proportion, or variance following -ci-. You didn't get an error message on that because Stata stopped due to the first problem. But if you just fix that, you will get an error message for this.
    I think what you want will be:
    Code:
    statsby mean = r(mean) ub = r(ub) lb = r(lb), by(gender year) clear: ci mean dependentvar
    Added: *What I said in 1. above isn't exactly right. If you specify neither -clear- nor -saving()- Stata assumes you want the results to replace the data in memory. However, if the data currently in memory have never themselves been saved, then Stata will not overwrite them without the explicit authorization to do so provided by the -clear- option. In other words, had your -statsby- command come before any changes to the data, you would not have gotten this message. So another solution to this problem would be to -save- the data before running -statsby-. But that only makes sense if you actually have a reason to save this modified data set. It's simpler just to specify -clear- or -saving()- in -statsby-.
    Last edited by Clyde Schechter; 27 Mar 2022, 16:00.

    Comment


    • #3
      Thank you som much Clyde, I understand now. Great explanation. However, the code does not produce a graph? Neither when I add a "line gender year" below.

      Comment


      • #4
        No, -statsby- does not produce graphs. You have to follow it up with the graph command you want. -line gender year- would not be the right one. Probably something more like -line mean year, by(gender) sort-.

        Comment

        Working...
        X