Announcement

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

  • #16
    do you have an indicator variable for the two groups; e.g., 0=group 1 and 1=group 2? if not, then set one up; you can then either (a) estimate two regressions using "if group==0" for the first and "if group==1" for the second (assuming that you called this variable "group") or (b) add interactions between this indicator variable and at least some of your other predictors

    Comment


    • #17
      Well, if you try the code in #12 above, it should run the two regressions. Just how you are going to compare the two groups after that isn't clear to me. If it's something you plan to do by eyeball or by hand, then you should be fine. But if you need to do further calculations based on the results of those regressions, only the final regression's results will still be in e(); all the earlier ones will be lost, so you will be unable to proceed.

      Without knowing just what kind of comparison you plan, it's hard to advise the best way to proceed, but for many purposes, using the -statsby- command, as suggested earlier by Rich Goldstein, will probably be your best choice.

      Comment


      • #18
        Hi,
        Sorry for the late reply. Thanks Clyde, I tried your proposed solution in #12 and it worked. So, thank you for that. Now, I tried to report the result with the outreg2 command but it just reported the last table (of the last group).
        What I did then is adding the bysort option to the outreg2 command but I got a table with repeated 2 columns of the last group!!
        So, any help with this please!

        Comment


        • #19
          You are encountering precisely the problem I raised in #17: when you use -by- only the results of the final regression remain in memory.

          You can't use -by- for this. You need to run a loop and store the regression estimates each time.

          Code:
          levelsof group, local(groups) // OPTIONALLY RUN THIS QUIETLY
          
          local estimates_list
          foreach g of local groups {
              regress y x1 x2 x3 if group == `g' // SEE NOTES BELOW
              estimates store e_`g'
              local estimates_list `estimates_list' e_`g'
          }
          outreg2 your_variable_list `estimates_list' using your_filename, your options
          Notes:
          1. This is coded assuming that group is a numeric variable taking on positive integer values. If group is a string variable, you may be able to simply place `g' within quotation marks in the -regress- command. That will work if the values taken on by group do not contain any embedded blanks, quotation marks, or other special characters: just letters, numbers, and underscores. But if the values of group do include blanks or special characters, the code will break at the -estimates store- command because e_`g' won't be a valid name for stored estimates. In that case you need to -encode- group, and replace each occurrence of group in the code with the name of the -encoded- variable.

          2. I am not an outreg2 user myself, so I am being deliberately vague and generic in the -outreg2- command above. This code is intended to get -outreg2- to use the results of all of your group-specific regressions. The details of the -outreg2- command itself (the italicized parts) I leave to you.

          Comment


          • #20
            Thanks a lot Clyde, but what do you mean by estimates_list! Sorry it's a silly question! But I can't see! I need a little more explanation please.
            Thanks.

            Comment


            • #21
              The overall operation of -outreg2- is that it can take the information from stored regression estimates and output it in the format you like. The syntax of that command, according to its help file, is:
              outreg2 [varlist] [estlist] using filename [, options] [: command]
              In that syntax, estlist is a list of the names of stored estimates.

              So to use this, you have to create a list of stored estimates. In your situation, this means you need to do a regression for each group, and then store its estimates under some name, and then you have to list all of those names in the -outreg2- command at the end.

              So in my code estimates_list is a local macro which is first set to the empty string. (I chose the name estimates_list hoping to make it clearer what it is for.) Then each time through the loop, a group-specific regression is performed, and its results are stored with a name e_`g' (where `g' is the number of the current group). Then the local macro estimates_list is revised to consist of its previous contents with this name e_`g' tacked on. So when the loop finishes, the local macro estimates_list will contain the names given to all the stored results of the regressions carried out in the loop. That list then appears as `estimates_list' in the final -outreg2- command, providing the command with the names of the stored estimates you want it to work with.

              I highly recommend you read the macro chapter in the [P] users manual. Although that manual is aimed at Stata programmers, the fact is that many analysis and data management problems are greatly facilitated by the use of macros. (Indeed, some are impossible to do without macros.) The time you invest in learning Stata macros will be amply repaid in short order.

              Comment


              • #22
                Thanks Clyde for your answer. It's quiet clear now. Thanks again.

                Comment


                • #23
                  @Clyde, from #6, how can I export regression results for all the groups (year) please?
                  I tried the following but it only gave me the results of the last year:
                  Code:
                  estimates store probit
                  bys year: outreg2 using regression0609, replace excel dec(3)
                  Thank you

                  Comment


                  • #24
                    You can't do this with -by-, because although it iterates through all the years, each time it -replace-s the results you had before. At the end, only the last year's results remain. Also, you have to iterate over the regression itself. So something along these lines:
                    [code]
                    levelsof year, local(years)
                    foreach y of local years {
                    probit whatever if year == `y'
                    outreg2 using regression0609_`y', replace excel dec(3)
                    }

                    Now, this will give you a separate spreadsheet for each year. There may be a way in outreg2 to get the results into a single spreadsheet with multiple tabs. I don't know, as I do not use -outreg2- myself.


                    Comment


                    • #25
                      Yes it gave separate excel files for each year but still, better than nothing
                      Thank you so much

                      Comment

                      Working...
                      X