Announcement

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

  • #16
    = file open __00000D using C:\Users\Emily XPS13\AppData\Local\Temp\ST_4330_000003.tmp, write replace
    This will generate the error as the quotation marks are stripped off the command. It should be

    Code:
      = file open __00000D using "C:\Users\Emily XPS13\AppData\Local\Temp\ST_4330_000003.tmp", write replace
    It should be easy to change this in the outreg2 ado file, but what I cannot figure out is how you were able to run the command without errors before but not now. I will have to look at the ado to specifically tell you what to change if someone else does not do it sooner.

    EDIT: Try the following:

    Code:
    viewsource outreg2.ado
    To get the location of the ado file in your C drive. Then go this location and open the ado file in Notepad. If you search this file, you will see

    Code:
    tempname labelsave
                    tempfile label_file
                    file open `labelsave' using `label_file', write replace
                    foreach var in `varname_list' {
                            if `"`var'"'~="_cons" & `"`var'"'~="Constant" {
                                    fvts_label `var'
                                    file write `labelsave' `"`var'"' _tab `"`fvts_label_list'"' _n
                            }
                    }
    Change this to

    Code:
    tempname labelsave
                    tempfile label_file
                    file open `labelsave' using "`label_file'", write replace
                    foreach var in `varname_list' {
                            if `"`var'"'~="_cons" & `"`var'"'~="Constant" {
                                    fvts_label `var'
                                    file write `labelsave' `"`var'"' _tab `"`fvts_label_list'"' _n
                            }
                    }
    That is, enclose it with quotation marks, save, restart Stata and I think this should solve it.

    Last edited by Andrew Musau; 04 Jan 2021, 15:47.

    Comment


    • #17
      Thanks, Andrew. I've made and saved the single change (adding in "") to my outreg2.ado file, as per your post 16 advice, then closed and re-opened Stata.
      So, the relevant part of my saved outreg2.ado file now reads:

      Code:
      tempname labelsave
              tempfile label_file
              file open `labelsave' using "`label_file'", write replace
              foreach var in `varname_list' {
                  if `"`var'"'~="_cons" & `"`var'"'~="Constant" {
                      fvts_label `var'
                      file write `labelsave' `"`var'"' _tab `"`fvts_label_list'"' _n
                  }
              }
      However, the same error is being generated as before when I try to run the outreg2 command:


      Code:
      . do "C:\Users\Emily XPS13\AppData\Local\Temp\STD3de4_000000.tmp"
      
      .         clear
      
      .         set more off
      
      .         clear 
      
      .         
      .         set mat 11000
      set matsize ignored.
          Matrix sizes are no longer limited by c(matsize) in modern Statas.  Matrix sizes are now limited by flavor of Stata.  See limits for more details.
      
      . 
      .         *** Emily's Current Laptop Directories ***
      .         
      .         cd "C:\Users\Emily XPS13\Desktop\HESAanalysis"
      C:\Users\Emily XPS13\Desktop\HESAanalysis
      
      .         global maindir "C:\Users\Emily XPS13\Desktop\HESAanalysis"
      
      .         global outputs "C:\Users\Emily XPS13\Desktop\HESAanalysis\AlmudenaHESAOutputs"
      
      .         global dofiles "C:\Users\Emily XPS13\Desktop\HESAanalysis\AlmudenaDoFiles"
      
      .         global statadata "C:\Users\Emily XPS13\Desktop\HESAanalysis\AlmudenaStataData"
      
      . 
      .         
      .         *** Open Dataset *** 
      .         
      .         use "$statadata/HESA_SBM_working.dta", clear
      
      .                 set more off
      
      .                 
      .         *** Regression ***
      . 
      .         reg lsalary16 BLACK ASIAN OTHER, robust   
      
      Linear regression                               Number of obs     =     56,060
                                                      F(3, 56056)       =     580.78
                                                      Prob > F          =     0.0000
                                                      R-squared         =     0.0231
                                                      Root MSE          =     .31382
      
      ------------------------------------------------------------------------------
                   |               Robust
         lsalary16 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
             BLACK |  -.1799856   .0058285   -30.88   0.000    -.1914095   -.1685617
             ASIAN |  -.1127993   .0040046   -28.17   0.000    -.1206482   -.1049503
             OTHER |  -.1054351   .0066931   -15.75   0.000    -.1185536   -.0923166
             _cons |   10.93335   .0014885  7345.04   0.000     10.93043    10.93627
      ------------------------------------------------------------------------------
      
      .         
      .         
      .         outreg2 using "$outputs/TableEthnic.xls", replace label dec(3) keep(BLACK ASIAN OTHER) addtext(Controls, NO, University Dummies, NO, Year Dummies, NO)
      invalid 'XPS13' 
      r(198);
      
      end of do-file
      
      r(198);

      However, when I check where the error occurs by adding back in:
      Code:
      set more off
      set trace on
      just before the outreg2 command, I can see the error is being triggered now in a different place, as shown below:

      Code:
          -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end outreg2.fvts_label ---
          - file write `labelsave' `"`var'"' _tab `"`fvts_label_list'"' _n
          = file write __00000D `"OTHER"' _tab `"Other"' _n
          - }
          - }
          - if `"`var'"'~="_cons" & `"`var'"'~="Constant" {
          = if `"_cons"'~="_cons" & `"_cons"'~="Constant" {
            fvts_label `var'
            file write `labelsave' `"`var'"' _tab `"`fvts_label_list'"' _n
            }
          - }
          - file write `labelsave' `"_cons"' _tab `"Constant"' _n
          = file write __00000D `"_cons"' _tab `"Constant"' _n
          - file write `labelsave' `"Constant"' _tab `"Constant"' _n
          = file write __00000D `"Constant"' _tab `"Constant"' _n
          - file close `labelsave'
          = file close __00000D
          - insheet using `label_file', clear
          = insheet using C:\Users\Emily XPS13\AppData\Local\Temp\ST_3de4_000003.tmp, clear
      invalid 'XPS13' 

      Comment


      • #18
        So basically, you have fixed the first error. Now you need to go to the ado file again and change

        Code:
        insheet using `label_file', clear
        to

        Code:
        insheet using "`label_file'", clear

        Hopefully it is only these two, but there may be more. If you fix all, it should run alright.

        Comment


        • #19
          OMG! Andrew (and also William), you are brilliant!

          Andrew, and for the benefit of anyone else reading this, I made the 2nd edit to my outreg2.ado file, as per your advice in post #18. I then checked with ctrl-f and found there was a third instance of `label_file' that was not enclosed in parenthesis. The full line where this third edit was needed actually was also identical to the line already mentioned in post #18. After making this 3rd "" edit, I then saved the outreg2.ado file, closed and reopened STATA, and my testing code now runs fully (same as what I show did not run fully in post #17 and several prior posts)!

          I checked it twice and also ran the full code for the table I was trying to generate with 5 regression models. All working now!

          Thank you both so, so, much! I have no idea why this was able to run before, as I think I do understand from the process we've followed now why it should not have run. I'd been using outreg2 on the same laptop for about a year and I believe I'd had the label option in use for all of that time as well.

          Now, at least I don't have to a massive bunch of edits to an entire paper's do-file or manually edit my tables. I'm going to save a note on the three changes I made to the outreg2.ado file in case needed for future reference, or there is a new version of it at some point. Thank you so much for your patience with explaining how to use the trace to diagnose the issue as well. I hope I will be able to do this more independently in future should the need arise - although I hope it does not arise soon!

          Comment


          • #20
            Ah, good debugging, Emily Pfefer. You nailed the lines where the problem occurred - that's so much better than a lot of trace output that gets posted on Statalist.

            I agree with you that (a) it seems like this should never have worked and (b) its likely that you have indeed successfully used the labels option before. It never occurred to me (as a non-Windows user) that the problem could be with the tempfiles (rather than with your using file), which on Stata for Mac (and linux I'd wager) are stored in a system directory rather than the user's directory.
            Code:
            . display c(tmpdir)
            /var/folders/xr/lm5ccr996k7dspxs35yqzyt80000gp/T/
            For the benefit of future readers, I want to pass along a tip that daniel klein gave on another topic where an existing community-contributed ado file needed to be corrected.

            Rather than locate outreg2.ado and open it in Notepad, it can be easier to just open the ado file in the Do-file editor with the following two commands.
            Code:
            findfile outreg2.ado
            doedit "`r(fn)'"
            then make the needed changes and save it.

            Comment


            • #21
              Good evening, I am working with xtable and I would like to export the output with outreg2, maybe could you help me who the code work?, I tried but I do not know how to use outreg2 with matrix(r(xtable)), thanks in advance

              Comment

              Working...
              X