Announcement

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

  • Dataset in memory has changed since last saved

    Dear Statalist,

    I am compiling my analysis code altogether. In my current preparation do file, I prepared the data and the code was running smoothly (for replication) until the syntax meant to generate a graph. The below part, after loading the data and doing subsequent code preparations, gives the following error message "No; dataset in memory has changed since last saved "

    Code:
    Graph_1: Testing if the diff. in average SWB of the two groups (stayers and leavers acc. to their declared return intentions) is significant
    
    preserve
    cap drop mean_swb
    bys sample1: egen mean_swb= mean(current_satisfaction)
    twoway (line mean_swb sample1) 
    ciplot current_satisfaction , by (return) //there is NO overlap, the difference is significant
    statsby, by(sample1 return) : ci mean current_satisfaction
    line mean sample1, by(return) sort
    restore
    Is there a way to fix this? I hope to have code running smoothly without interruptions showing the replication of my analysis. Thank you in advance!


  • #2
    -statsby- creates a new data set containing the results it has saved. It must either be permitted to overwrite the existing data in memory (by specifying the -clear- option) or save those results in an external data set (by specifying the -saving()-) option. When neither option is specified, it will try to put the results into memory. But Stata has a general rule that you cannot overwrite the data in memory if it has been changed since it was last saved unless the command explicitly OKs that through a -clear- option. The command that created the swb_mean changed the data in memory, but you never saved that change in a subsequent command. So Stata is stuck: it has no place to put -statsby-'s results, so it breaks with that error message.

    As I am not clear about what you are trying to do here, I can't advise you specifically on the change. I can only say that your -statsby- command must have either a -clear- or -saving()- option specified. But I don't know which. I think it's the -saving()- option because I think that the subsequent -line- command needs the data that is in memory before -statsby-, not the -statsby- results, but I'm not sure of that.

    Comment


    • #3
      Dear Clyde, thank you so much for your quick response and help! I wanted to produce some kernel density graphs after this one and at the end of the do file, I inserted a do command to execute my regressions in the other do file. Indeed, the clear option solved my problem. Thank you so much! Here is the line after specifying clear in it: statsby, by(sample1 return) clear: ci mean current_satisfaction

      Comment

      Working...
      X