Announcement

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

  • Odd problem with 'Collapse' function -- runs without errors but the resulting dataset isn't actually "collapsed"

    Hey guys --


    I'm having an odd issue where sometimes (not always) the same piece of code containing a "collapse" function executes without errors, but then the un-collapsed dataset is still loaded into Stata. And as I said sometimes it won't happen, or sometimes if I copy paste the statement and run it a second time immediately after it will work. This seems like a hard thing to explain properly and I may sound confusing, so let me give you the example:

    I have a monthly data set of ID numbers and dollar amounts across 6 months (so 6 observations for each ID number, one for each month) -- here is a small sample of dummy data with the same structure & fields:
    Month ID Balance
    Sep-14 1 100
    Oct-14 1 90
    Nov-14 1 95
    Dec-14 1 100
    Jan-15 1 80
    Feb-15 1 95
    Sep-14 2 25
    Oct-14 2 18
    Nov-14 2 29
    Dec-14 2 30
    Jan-15 2 30
    Feb-15 2 31
    Sep-14 3 5
    Oct-14 3 7
    Nov-14 3 3
    Dec-14 3 4
    Jan-15 3 9
    Feb-15 3 3
    Trying to get the resulting dataset:
    ID mean_balance
    1 93.33
    2 27.17
    3 5.17

    I want to use the following code for this:

    collapse (mean) mean_balance = Balance , by(ID)

    However when I run this portion of code from the do file editor, it will show that it ran properly without any errors in the results window, but when I browse the dataset it is exactly as before (still containing the monthly values) as if literally nothing was ran. Also -- if I include a 'save' statement right after the collapse [save "D:\Average_Bals.dta" , replace], and then I open that saved dataset after running the code, the saved dataset is collapsed properly, even though it looked to be uncollapsed in the data browser after running the collapse.

    I know that it is important to do my own research on the issue and show what I've tried thus far to remedy the problem, but I could not find anything regarding this type of issue after a couple hours of browsing through the stata manual & Google, and outside of closing Stata, deleting temp files, and rebooting my computer, I am at a complete loss as to what else to try.

    Also my specs for my computer & Stata are as follows:
    Stata Version:
    Stata 13.1 MP - 4 Core License

    (I don't think the problem is OS specific, but just including all information just in case):
    Computer Stata is being run from:
    OS: Windows Server 2012 R2 Standard; 64 Bit
    Processor: Intel(R) Xeon(R) CPU E5-2650 @ 2.0 GHz; x64-based
    RAM: 324 GB



  • #2
    It appears to me that when something outside the data browser changes the data, the data browser does not always immediately update what it displays. I was able to reproduce the behavior you observed, but not consistently. Perhaps closing the window and reopening it will solve your problem, or issuing the list command after the collapse will demonstrate that the data has been replaced with the collapsed data.

    Comment


    • #3
      One other thought. If there is a -preserve- command somewhere earlier in the code, when you reach the end of the program, the -preserve-d data is brought back and would clobber the -collapse-d results.

      Comment


      • #4
        Thank you for your replies.

        William -- yes it does not happen consistently for me either, can't seem to find a pattern, just sometimes it happens and sometimes it doesn't..And I have tried that but it doesn't seem to be an issue isolated to the databrowser, as if I even try issuing a command against "mean_balance" afterwards it will throw an error that "mean_balance doesn't exist"..

        Clyde -- There is preserve statements in the code, but I didn't think the preserved data comes back unless you specifically issue a "restore" command; you're saying that this is not always the case?

        Comment


        • #5
          There is preserve statements in the code, but I didn't think the preserved data comes back unless you specifically issue a "restore" command; you're saying that this is not always the case?
          That is correct. While you can -restore- the -preserve-d data sooner by explicitly issuing a -restore- command, if you never issue a -restore-, the data comes back at the end of the program, do-file, (or highlighted block of commands within a do-file) that invoked the -preserve-. It's in the online help file for -preserve-:

          When the program or do-file concludes, the user's data are automatically restored.

          Comment

          Working...
          X