Announcement

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

  • Error regarding Stata Versions

    Hi folks,

    I am having an issue with Stata versions that is perplexing and have not been able to find a solution online.

    In my .do file, I bring in some data and collect and save a table of estimates from it. (I had originally saved it as a temp file, as I do other ado created files, but am now saving it as a .dta file to the working folder.) Later in the .do file I try to merge that file with a working file and I get the error, "file G:\Shared drives\siting_db\lbwmr\data\2024\temp\ptech.dta from more recent version of Stata; type update query to see if an update to Stata is available and look at https://www.stata.com/ to see if a new version of Stata is available."

    I am using StataNow/MP 19.5 and it is up to date. The perplexing thing is the file is created from within the same version of Stata.

    I will note that a previous version of this semi-annually run script used the .table, replace command, so I had to get up to speed on the .table, then collect save command. I wonder if I am doing something wrong there. That set of commands is as follows:

    use "$temp\lbwmr_data.dta", clear
    qui table p_id [fweight= i_tnum] if p_year>=1998, stat(mean t_rd t_rsa t_hh t_np_cap t_sp) nototals
    collect save "$temp\ptech.dta" , replace

    And the command that is giving me the error is:
    merge 1:1 p_id using "$temp\ptech.dta", keep(match master) keepusing(t_rd_avg t_rsa_avg t_hh_avg t_cap_avg t_sp_avg) nogen //adding the tech averages

    Interestingly, I merge in a few other temp files I save earlier in the.do file, and they merge without this version error.

    I suspect someone will see the error in my ways.

    Thank you, in advance,

    Ben

    Ben Hoen
    Berkeley Lab

  • #2
    I think the error message you are getting is slightly misleading. When you use -collect save-, you do not get a .dta file. You get an .stjson file. When you then issue the -use- command, even though you called the file ....dta in the command, Stata assumes that any file accessed through -use- is a .dta file. But your file is not a .dta file, even though it was (mis)named with the .dta filename extension. So when it tries to read it as if it really were a .dta file, it doesn't find the headers and other metadata that it expects to see in a .dta file. I guess Stata can't figure out exactly what the problem is, so it gives the only error message relating to incorrect file format it has available, which misstates the problem as one of versioning. It's not about versioning.

    So when you save this file with -collect save- you get an .stjason file, and to subsequently read it back in, you need -collect use-, not -use- and not -merge-, which also works only with actual .dta files.

    Added: I don't know what you are aiming for when you try to -merge- the -collect save- results with some bona fide .dta files. So I can't advise you how to do this. (And my understanding of Stata collections is pretty primitive anyway.) But I think you will have to -collect use- this .stjson file and then, in some way (I don't know what way), extract what you want from it into a real .dta file and then -merge- that.
    Last edited by Clyde Schechter; 17 Jul 2025, 14:46.

    Comment


    • #3
      Clyde describes what is going on.

      I'll just add that you can use prefix version 16: in your call to table, but you need to revert your code to the old syntax, to get the old behavior you are familiar with.

      Comment


      • #4
        Ah hah. Thanks, Clyde and Jeff/ That makes a lot of sense. I will be able to find some way to work this out, either reverting, thanks Jeff, or getting back to a .dta file, thanks Clyde. I am also glad to hear that I am not the only one who is struggling with collections. I do know they provide a tremendous range of benefits, I just need to learn how to access them. Cheers!

        Comment


        • #5
          I can report back that the reverting worked perfectly. But, alas, this old dog failed to learn a new trick. :-(

          Comment

          Working...
          X