Announcement

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

  • Felix Kaysers I'm not sure I understand the issue in #240: I'm especially not sure I understand this "restore" centric workflow you describe. You can store regression estimates and use them later (or not) if you like. You can also store tables (as collections) and reference them by name later in putdocx. Here is one simple workflow with -estimate table- but there are definitely other viable workflows that should be basically equivalent to whatever you are doing in R.

    Code:
    cd "H:\Users\Daniel Schaefer"
    sysuse auto, clear
    
    regress price mpg
    estimates store model1
    
    regress price mpg i.foreign
    estimates store model2
    
    regress price mpg i.foreign weight
    estimates store model3
    
    putdocx begin
    
    estimates table model1
    putdocx table model1 = etable
    
    estimates table model2
    putdocx table model2 = etable
    
    estimates table model3
    putdocx table model3 = etable
    
    putdocx save testdoc, replace

    Comment


    • Felix Kaysers #240: there are also add-on programs, such as -regsave-, that will store results in a Stata dataset. For one example of a fully reproducible workflow in Stata, see this guide.
      Associate Professor of Finance and Economics
      University of Illinois
      www.julianreif.com

      Comment


      • Daniel Schaefer Julian Reif Thank you for your questions and suggestions. I see now that my phrasing was unclear and I need to clarify. I was talking about incorporating information from different models in text form. To take an example from Julian Reif's QJE paper on well-being, on pages 1786-1787 you write "Table II, column (3), first row reports that employees who completed the screening and HRA spent, on average, $115.3 per month less on health care in the 13 months prior to our study than employees who did not participate. This pattern of advantageous selection is strongly significant using conventional inference (p = .027) and remains marginally significant after adjusting for the five outcomes in this family (family-wise p = .082)." Assuming that the p-values come from two different regressions to reference the p-values in text form in putdocx, the easiest way I could find is to store the regressions results in a matrix and then use display to show the matrix cell in putdocx. My example uses the ssc library estout/esttab but I have also used estimates store to get my results. So, in general, I couldn't find any documentation about this when I was searching and asked in the Stata Forum for help. Second, using display makes the code unreadable really fast, and even more so, if I want to use the symbol for beta for example.

        Code:
        sysuse auto, clear
        
        eststo model1: regress price mpg
        eststo model2: regress price mpg foreign
        
        foreach mod of global eststo {
            estimates restore `mod'
            global `mod'_r2 = e(r2)
            ereturn display
            matrix mtx_`mod' = r(table)
        }
        
        putdocx begin
        putdocx paragraph
        putdocx text ("In both Models, the effect of mpg on price is negative (Model 1: `:di %5.3f `=mtx_model1["b", "mpg"]'', Model 2: `:di %5.3f `=mtx_model1["b", "mpg"]'').")
        putdocx save Test.docx, replace
        __________________________________________________ __________

        Cheers, Felix
        Stata Version: MP 18.0
        OS: Windows 11

        Comment


        • Is it possible to increase the number of estimation results that can be stored using -estimates store- or -estimates hold-?

          Comment


          • for dtable to keep 1 row only for those dichotomus variables (e.g. yes or no), and to organize subgroups from greater or less when based on %

            Comment


            • If X is a dichotomous variable coded as 0 = no and 1 = yes, you can specify X as 1.X in the -dtable- command and you will get only the yes value. Similarly, if you prefer only the no value, specify 0.x. It is when you specify X as i.X or just X inside of -factor()- that you get both values included.

              Comment


              • I would like to be able to obtain confidence distributions after various kinds of estimates; see Marschner, IC (2024), "Confidence distributions for treatment effects in clinical trials: posteriors without priors," Statistics in Medicine, 43: 1271-1289; note that although this article is recent, the idea is not and can be found in Cox, DR (1958), "Some problems with statistical inference," Annals of Mathematical Statistics, 29: 357-372; Marschner also says the idea was implicit in the 1930's writing of Neyman and of Fisher (see the article for cites)

                Comment


                • More sophisticated version of the new table command in Stata 18. It still isn't as functional to just create publication ready tables as R Markdown is.
                  Also, vast improvements in data visaulisation capabilities including flexibility in editting.

                  Comment


                  • I'm a little confused by #248 since R Markdown doesn't really create tables on its own. R markdown is just a markup (markdown) language like html. It essentially wraps R output generated by other packages in well-formatted text.

                    In my opinion the real problem with -tables- and -collections- is that they are arcane and difficult to learn. That said, the full system including -tables-, -collections- and -putdocx- (among others) is very flexible and sophisticated. I can see why someone might prefer the dplyr package (bundled in R with tidyverse), but I don't agree that it's more sophisticated than -tables- and -collections-.

                    Comment


                    • Allow editing post titles or posts immediately after posting (e.g. 6 hours), to clarify things that are unclear from the beginning.

                      Comment


                      • A few minor but impactful changes on my wishlist. Apologies if there are easy ways to do the following that I'm not aware of:
                        • Ability to hit the up arrow in the console to retype the last used command (e.g., RStudio)
                        • Option to output the 95% CI with the -alpha- command
                        • Native -omega- command (again with 95% CI option)
                        • As others have said, option in -tab- to display both the value and the label at the same time.
                        Last edited by Erik Reinbergs; 13 Apr 2024, 17:45. Reason: typo

                        Comment


                        • FYI, page up key by default fills the console with the last command. I know not every keyboard has page up and I'm not sure whether or not you can change the default to up arrow.

                          Comment


                          • I would look for ways to remap keys of your keyboard: <strg><arrow up> and <strg><arrow down> to <page up> <page down> (and <strg><left> and <strg><right> to <home> and <end>). How to depends on your operating system, some require to install additional software to do so. Google search shows several ways for Windows and MacOS.

                            Comment


                            • - Simulation-based residual diagnostic plots for hierarchical (multi-level/mixed) regression models. The DHARMa R package.
                              - More customizable table1
                              - Add the do-file as a subwindow to the main stata window with the console. Mainly to skip having to click back the do-file window every time you change programs.
                              - Add simple examples to each command description, with code AND output.
                              - Give encode a replace option
                              Last edited by Laura Vossen Engblom; 15 Apr 2024, 04:45.

                              Comment


                              • Maybe I am missing this function somewhere else, but handling factor variables in programs can be real pain. I wish there would be an equal function to tsunab for factor variables which returns a list which I can directly use. For example

                                Code:
                                webuse auto 2
                                fvunab tmp: mpg i.foreign
                                Returns mpg i.foreign and
                                Code:
                                fvexpand mpg i.foreign
                                returns mpg 0b.foreign 1.foreign, where the 0b indicates that this is the baseline. In any following code 0b.foreign is treated as to be omitted. Typing
                                Code:
                                . sum mpg 0b.foreign 1.foreign
                                
                                    Variable |        Obs        Mean    Std. dev.       Min        Max
                                -------------+---------------------------------------------------------
                                         mpg |         74     21.2973    5.785503         12         41
                                             |
                                     foreign |
                                    Foreign  |         74    .2972973    .4601885          0          1
                                leaves out the base line category. I see the benefit in it when parsing the variable list for regressions. However there are situations where one want to obtain 0.foreign and 1.foreign, for example when building matrices with results.

                                I think (!) this is inconsistent with the behavior of fvrevar.
                                Code:
                                fvrevar mpg i.foreign
                                creates two temporary variables for foreign, namely 0.foreign and 1.foreign. However there is no way to obtain the corresponding labels (or variable names) for the two temporary variables.

                                My suggestion would be to add either a function "noomit" (or similar) to fvexpand which returns mpg 0.foreign 1.foreign. Then I can match the result with temporary variables from fvrevar. Preferred would be to combine fvrevar and fvexpand so that fvrevar also returns the expanded list of variablenames. I think this can be easily programmed, but it would make life much easier if there would be a stable Stata build-in solution.

                                If this already exists and I just overlook it, I'd be very happy
                                Last edited by JanDitzen; 15 Apr 2024, 06:01.

                                Comment

                                Working...
                                X