Announcement

Collapse
No announcement yet.
This is a sticky topic.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 1. Make it possible to create tempfiles in one line instead of two.

    Instead of:

    Code:
    tempfile a
    save `a'
    Make it:

    Code:
    temps a
    2. Add the ability to sort descending with bysort.

    Currently, I have to:

    Code:
    gsort id -age
    bys id: keep if _n==1
    When I want to:

    Code:
    Bys id (-age): keep if _n==1
    3. Add the "stable" option to "gsort," with the same functionality as in the "stable option in "sort."

    Comment


    • request that StataCorp add the cumulative probability model (called by Agresti the cumulative link model); some cites:

      Agresti, A (2013), Categorical data analysis, third edition, Wiley (has very little but does have an intro)

      Liu, Q, et al. (2017), "Modeling continuous response variables with ordinal regression", Statistics in Medicine, 36:4316-4335

      Tian, Y, et al. (2020), "An empirical comparison of two novel transformation models," Statistics in Medicine, 39: 562-576

      Tian, Y, et al. (2024), "Addressing multiple detection limits with semiparametric cumulative probability models", Journal of the american statistical association, 119 (546): 864-874

      Comment


      • Todd Jones #301 I agree with the spirit here in having wanted something similar from time to time.

        That said, your request 1 is programmable by users and your example in request 2 is equivalent, I think, in intent to

        Code:
        collapse (max) age , by(id)
        although not if other variables are needed too. Otherwise

        Code:
        bysort id (age) : keep if _n == _N
        except that missing values would mess that up too.
        Last edited by Nick Cox; 26 Jun 2024, 19:58.

        Comment


        • Nick Cox #303. Thanks for the thoughts!

          For request 2, I am often finding myself doing something like the following (where I need to retain multiple variables), so your second solution is nearly what I need modulo the missing value issue that you bring up. Note that 1) there are easier ways to perform what is done in this MWE but in reality I might do a lot more than this in the preserve/restore block, and 2) this MWE doesn't suffer from the missing value issue, so your "bysort id (age) : keep if _n == _N" solution would work in this case:

          Code:
          sysuse sandstone, clear
          gen n=_n
              preserve
              keep if col==2
              gsort nor -n
              by nor: keep if _n==1
              rename depth d_est
              tempfile m
              save `m'
              restore
          merge m:1 nor using `m', keepusing(d_est)
          For request 1, I would love to and have tried to create a program for SSC that does exactly this, but I can't figure out how to make it work. It seems like defining the tempfile in a program prohibits it from being used outside that program, even if one uses "Execute (include)".

          This is what I want to do:

          Code:
          sysuse auto2, clear
          tempfile y0
          save `y0'
          
          use `y0', clear
          Except that instead of the separate "tempfile" and "save" lines, I want to create the tempfile using a user-created "temps" command.

          Here is what I have tried:

          Code:
          sysuse auto2, clear
          
          capture program drop temps
          program define temps
          args y
          tempfile `y'
          save ``y''
          end
          
          temps y1
          
          use `y1', clear
          This does create a tempfile, but I cannot access it and get the "invalid file specification" error.
          Last edited by Todd Jones; 27 Jun 2024, 14:44.

          Comment


          • 1) An option when saving to exclude all temporary variables, or at least the ability to drop all temporary variables en masse. (Having to drop tempvars by name before saving makes tempvars more trouble than they're worth.)
            2) The ability to sort tables by some variable, for example so I can arrange a table of summary statistics to put the rows in decreasing values of the mean of something
            3) In frames, the ability to create a new frame and switch to it in one command

            Comment


            • Re #304: I'm virtually certain that this cannot be done in existing Stata, and I think making it possible would be a bad idea.

              The whole idea of a tempfile is that it will be eliminated as soon as the program that creates it ends. This means that you don't have to write code to erase it. And it also means that if the program that creates it ends abnormally, the temfile will still be eliminated. It keeps your mass storage devices from getting cluttered up with files that are not useful.

              What you can do in Stata that I think would serve the need you are feeling, but without breaking the benefits of the existing tempfile system is this. You can write a program that creates the contents of the tempfile you want to write, and have that program take as an argument or option the name of a file to save it in. Then, in the program that calls that program you can declare a tempfile and then pass that local macro to the program that creates the content and saves it, and then come back. Here's what the code looks like:

              Code:
              clear*
              
              capture program drop create_file
              program define create_file
                  args filename
                  sysuse auto, clear
                  save `filename'
                  clear
                  exit
              end
              
              tempfile test_it_out
              create_tempfile `test_it_out'
              
              use `test_it_out', clear
              Because tempfile `test_it_out' is created in the top-level program, it remains accessible after program create_file returns. Moreover, program create_file is flexible: you can pass it the name of a tempfile, or you can pass it the name of a permanent file, and it will respect your wishes either way. And tempfile `test_it_out' will automatically be eliminated once the calling program terminates.

              Comment


              • On #301 (request #1 only):

                This is indeed something that only StataCorp could implement. Should they? I don't think so. Saving a (sub-)dataset to disk is only one of the various ways to use temporary files. How much time would you like StataCorp to spend on implementing (and documenting!) such a limited use case so we can save -- what -- a couple of seconds, typing one line instead of two?

                Here is how you can write one line:

                1. Define a Mata function:

                Code:
                version 18
                
                mata :
                
                void st_tempsave(string scalar lclname)
                {
                    st_local(lclname,st_tempfilename())
                    stata("save "+st_local(lclname))
                }
                
                end
                2. Use the Matra function in your do-files, e.g.

                Code:
                . sysuse auto
                (1978 automobile data)
                
                . preserve
                
                . keep if foreign
                (52 observations deleted)
                
                . mata : st_tempsave("m")
                file C:\Users\klein\AppData\Local\Temp\ST_2f40_000002.tmp saved as .dta format
                
                . use "`m'" , clear
                (1978 automobile data)
                
                . tabulate foreign
                
                 Car origin |      Freq.     Percent        Cum.
                ------------+-----------------------------------
                    Foreign |         22      100.00      100.00
                ------------+-----------------------------------
                      Total |         22      100.00
                
                . restore


                2a. If that still is too much typing, define the function in a local macro

                Code:
                local temps mata : st_tempsave("m")
                then call that in your code

                Code:
                . local temps mata : st_tempsave("m")
                
                . sysuse auto
                (1978 automobile data)
                
                . preserve
                
                . keep if foreign
                (52 observations deleted)
                
                . `temps'
                file C:\Users\klein\AppData\Local\Temp\ST_2f40_000002.tmp saved as .dta format
                
                . use "`m'" , clear
                (1978 automobile data)
                
                . tabulate foreign
                
                 Car origin |      Freq.     Percent        Cum.
                ------------+-----------------------------------
                    Foreign |         22      100.00      100.00
                ------------+-----------------------------------
                      Total |         22      100.00
                
                . restore
                The downside of 2a is that once you define the local temps, you cannot change the local macro name for the temporary file.
                Last edited by daniel klein; 28 Jun 2024, 07:52.

                Comment


                • Thank you very much for your comments, Clyde Schechter and daniel klein!

                  Comment


                  • I would like to see a small addition to the -dataex- command, whereby it would add to its existing output the commands necessary to replicate the -xtset-, -tsset-, or -stset- of the data set, where applicable.

                    While in most situations this information is not needed, or, in most of the panel data sets that appear in questions posted on Statalist, readily guessed, the post at https://www.statalist.org/forums/for...eshold-command is an example of a problem that could not be solved without this information. It was solved by Hemanshu Kumar , who used an attachment of the entire data set provided by O.P. Knowing how the data had been -xtset- was key to the solution of the problem, and could not have been reckoned from inspection of the data as the panel variable had already been removed. Admittedly, situations like this don't arise often, but I believe it would be a very simple matter to extend -dataex- in this way. Doing so will make -dataex- more useful and decrease the frequency with which attachments are needed.

                    Comment


                    • For import excel: the ability to import an entire workbook (with multiple sheets) at once, assigning each sheet to a different data frame. (Presumably an option would specify what to do if any worksheets had the same names as existing frames.) (Currently the need to loop through every worksheet is creating a substantial delay in what would otherwise be a quite quick program, presumably because of delays from the secure server where the excel documents are stored. I'd like to send the fewest possible number of distinct requests to that server.)
                      For import excel: the ability to provide passwords to open locked workbooks
                      Last edited by Stephen Weinberg; 08 Jul 2024, 10:08.

                      Comment


                      • Bivariate Logit command similar to biprobit command. Please there is any available alternative to estimate a bivariate binary logit model on stata, I would be happy to learn. I am more interested in the correlation between the errors in the two outcome variables. Can I use mannual method to generate the errors and test for correlation between them?

                        Comment


                        • Originally posted by Chekwube Madichie View Post
                          Bivariate Logit command similar to biprobit command. Please there is any available alternative to estimate a bivariate binary logit model on stata, I would be happy to learn. I am more interested in the correlation between the errors in the two outcome variables. Can I use mannual method to generate the errors and test for correlation between them?
                          Hello Chekwube Madichie. Your request in #311 reminded me of the following discussions in an SPSS forum several years ago: I wonder if you could use the same approach (i.e., include an indicator variable for DV) with -melogit- to obtain a multivariate logit model.

                          PS- You could also take a look at:
                          Code:
                          ssc describe mulogit
                          I am somewhat suspicious, however, that the author is talking about models with multiple explanatory variables (multivariable), not multiple outcome variables (multivariate).
                          --
                          Bruce Weaver
                          Email: [email protected]
                          Version: Stata/MP 18.5 (Windows)

                          Comment


                          • Add zoom in/out functionality to Stata output and Data/editor

                            Comment


                            • I would like to run moderating effect using latent variables in SEM.

                              Comment


                              • I have a small user interface related request.
                                Given that tabs in web browsers (and other programs) have become very common, so has the option to close them using a middle button click on a mouse. So I think there's now some implicit expectation to be able to close tabs with a middle click when working with modern software. It would be nice if this were implemented in Stata as well so we would be able to close do-file editor and viewer tabs using a middle click instead of aiming for the tiny "x" each time.
                                Last edited by Evgeny Saburov; 20 Jul 2024, 08:34.

                                Comment

                                Working...
                                X