Announcement

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

  • Looping over if statements

    I want to write code that loops over various if conditions in a regression.

    I have data like this:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte id str16 prov int year byte age str5 age_gp str22 prov_age_gp byte(female immigrant white) long income byte(hs satisfied good_health)
      1 "Ontario"          2014 33 "old"   "Ontario-old"            1 0 1 100407 0 1 1
      2 "Ontario"          2020 27 "old"   "Ontario-old"            0 1 1  74657 1 1 1
      3 "Ontario"          2020 45 "old"   "Ontario-old"            0 1 1  83161 0 1 0
      4 "Ontario"          2020 23 "young" "Ontario-young"          1 1 1  75722 1 0 1
      5 "Ontario"          2020 50 "old"   "Ontario-old"            0 1 1  57515 0 0 1
      6 "Ontario"          2014 12 "young" "Ontario-young"          0 1 1 116117 0 1 0
      7 "Ontario"          2018 23 "young" "Ontario-young"          0 1 0  92396 1 0 1
      8 "Ontario"          2017 14 "young" "Ontario-young"          1 0 0  31846 1 1 0
      9 "Ontario"          2018 13 "young" "Ontario-young"          1 1 1  97230 0 1 0
     10 "Ontario"          2016 29 "old"   "Ontario-old"            1 1 0 146051 0 1 1
     11 "Ontario"          2015 12 "young" "Ontario-young"          1 1 0  39582 1 1 0
     12 "Ontario"          2016 28 "old"   "Ontario-old"            1 0 1 115098 1 1 0
     13 "Ontario"          2020 39 "old"   "Ontario-old"            0 0 0  69452 0 0 0
     14 "Ontario"          2017 19 "young" "Ontario-young"          1 1 1  46980 0 1 0
     15 "Ontario"          2014 32 "old"   "Ontario-old"            1 1 0  86176 0 0 1
     16 "Ontario"          2018 19 "young" "Ontario-young"          0 1 0 136418 0 0 0
     17 "Ontario"          2016 48 "old"   "Ontario-old"            0 1 0   2678 0 0 0
     18 "Ontario"          2014 21 "young" "Ontario-young"          0 0 0  93515 1 0 1
     19 "Ontario"          2019 31 "old"   "Ontario-old"            1 1 1  47945 1 1 1
     20 "Ontario"          2016 24 "young" "Ontario-young"          0 1 0  38551 0 1 1
     21 "Ontario"          2015 20 "young" "Ontario-young"          0 1 1  27645 1 1 1
     22 "Ontario"          2019 46 "old"   "Ontario-old"            0 1 1  62639 0 1 1
     23 "Ontario"          2017 46 "old"   "Ontario-old"            1 1 0 130286 1 1 0
     24 "Ontario"          2018 38 "old"   "Ontario-old"            0 1 1  52823 0 0 0
     25 "Ontario"          2016 41 "old"   "Ontario-old"            0 1 0 148866 1 0 0
     26 "Ontario"          2014 41 "old"   "Ontario-old"            0 0 1  42689 1 1 0
     27 "Ontario"          2016 30 "old"   "Ontario-old"            1 1 1  26349 1 0 1
     28 "Ontario"          2014 50 "old"   "Ontario-old"            1 0 1 146965 1 1 0
     29 "Ontario"          2017 33 "old"   "Ontario-old"            0 0 1 144849 0 1 0
     30 "Ontario"          2020 36 "old"   "Ontario-old"            0 0 0  44745 1 1 1
     31 "Ontario"          2018 15 "young" "Ontario-young"          0 0 1  36163 0 1 0
     32 "Ontario"          2015 47 "old"   "Ontario-old"            1 0 0  87398 0 0 1
     33 "Ontario"          2017 23 "young" "Ontario-young"          0 0 1  87833 0 1 0
     34 "Ontario"          2015 31 "old"   "Ontario-old"            0 1 0  19675 0 0 1
     35 "Ontario"          2016 25 "old"   "Ontario-old"            0 0 1 141300 0 1 0
     36 "Ontario"          2014 39 "old"   "Ontario-old"            0 1 0  95323 1 1 1
     37 "Ontario"          2018 17 "young" "Ontario-young"          1 1 1  26585 0 0 0
     38 "Ontario"          2018 29 "old"   "Ontario-old"            1 0 1 110093 1 1 1
     39 "Ontario"          2019 21 "young" "Ontario-young"          1 0 0  48938 1 0 1
     40 "Ontario"          2015 45 "old"   "Ontario-old"            0 0 0 106064 1 0 1
     41 "Ontario"          2015 38 "old"   "Ontario-old"            0 0 1 113473 0 0 0
     42 "Ontario"          2019 42 "old"   "Ontario-old"            0 0 0  43939 0 0 0
     43 "Ontario"          2017 41 "old"   "Ontario-old"            1 1 1 133062 1 1 1
     44 "Ontario"          2019 32 "old"   "Ontario-old"            0 0 1 126149 1 0 1
     45 "Ontario"          2015 46 "old"   "Ontario-old"            1 0 1 137881 0 1 1
     46 "Ontario"          2015 31 "old"   "Ontario-old"            1 1 0 123258 0 1 0
     47 "Ontario"          2020 20 "young" "Ontario-young"          0 1 1  75791 1 1 0
     48 "Ontario"          2016 45 "old"   "Ontario-old"            1 1 1 112068 1 1 1
     49 "Ontario"          2016 23 "young" "Ontario-young"          1 0 1  51956 0 0 1
     50 "Ontario"          2016 20 "young" "Ontario-young"          0 0 1   6505 1 0 0
     51 "Alberta"          2018 47 "old"   "Alberta-old"            0 0 1    568 0 1 0
     52 "Alberta"          2017 34 "old"   "Alberta-old"            1 0 0    439 1 1 0
     53 "Alberta"          2020 26 "old"   "Alberta-old"            1 0 0 115646 0 0 1
     54 "Alberta"          2014 41 "old"   "Alberta-old"            0 0 0  48910 1 1 0
     55 "Alberta"          2016 36 "old"   "Alberta-old"            0 0 1 102959 0 1 1
     56 "Alberta"          2019 45 "old"   "Alberta-old"            1 1 0  25057 1 1 0
     57 "Alberta"          2016 36 "old"   "Alberta-old"            1 1 1 114133 1 1 1
     58 "Alberta"          2015 30 "old"   "Alberta-old"            0 1 1 111965 1 1 1
     59 "Alberta"          2016 18 "young" "Alberta-young"          0 1 1 142191 0 0 0
     60 "Alberta"          2015 41 "old"   "Alberta-old"            0 0 0  40717 0 1 0
     61 "Alberta"          2014 41 "old"   "Alberta-old"            0 0 0 101012 1 1 1
     62 "Alberta"          2018 19 "young" "Alberta-young"          1 0 0 127749 0 0 1
     63 "Alberta"          2017 46 "old"   "Alberta-old"            1 0 0  48383 0 0 0
     64 "Alberta"          2014 31 "old"   "Alberta-old"            0 1 1  41787 1 1 0
     65 "Alberta"          2014 48 "old"   "Alberta-old"            1 0 0  77192 1 0 1
     66 "Alberta"          2017 21 "young" "Alberta-young"          1 0 0  87067 1 1 0
     67 "Alberta"          2015 13 "young" "Alberta-young"          0 0 0  16935 1 1 0
     68 "Alberta"          2017 17 "young" "Alberta-young"          1 1 1 110079 0 1 1
     69 "Alberta"          2015 18 "young" "Alberta-young"          0 0 1  43234 0 1 1
     70 "Alberta"          2015 45 "old"   "Alberta-old"            1 1 0    861 0 0 1
     71 "Alberta"          2015 32 "old"   "Alberta-old"            0 1 1  32675 1 0 1
     72 "British Columbia" 2014 22 "young" "British Columbia-young" 0 1 0 126936 1 1 0
     73 "British Columbia" 2019 19 "young" "British Columbia-young" 1 0 0  18763 0 0 0
     74 "British Columbia" 2020 13 "young" "British Columbia-young" 1 0 0  78998 1 1 1
     75 "British Columbia" 2015 37 "old"   "British Columbia-old"   0 0 1  76340 0 1 0
     76 "British Columbia" 2018 35 "old"   "British Columbia-old"   1 1 1  75289 0 0 0
     77 "British Columbia" 2019 26 "old"   "British Columbia-old"   1 1 0   4810 0 0 1
     78 "British Columbia" 2020 41 "old"   "British Columbia-old"   1 1 1 142516 1 1 0
     79 "British Columbia" 2015 35 "old"   "British Columbia-old"   0 1 0 105552 1 1 1
     80 "British Columbia" 2015 12 "young" "British Columbia-young" 0 0 1 129348 0 0 0
     81 "British Columbia" 2015 46 "old"   "British Columbia-old"   0 1 0  78976 0 0 0
     82 "British Columbia" 2016 46 "old"   "British Columbia-old"   0 1 0  73313 1 0 1
     83 "British Columbia" 2014 26 "old"   "British Columbia-old"   0 0 1 110565 1 1 0
     84 "British Columbia" 2016 17 "young" "British Columbia-young" 1 1 1  54889 1 1 0
     85 "British Columbia" 2016 21 "young" "British Columbia-young" 0 1 0 146396 1 0 1
     86 "British Columbia" 2020 16 "young" "British Columbia-young" 0 1 1  20529 0 0 1
     87 "British Columbia" 2017 23 "young" "British Columbia-young" 0 1 1  95769 1 0 0
     88 "British Columbia" 2016 19 "young" "British Columbia-young" 1 0 1  86253 0 1 0
     89 "British Columbia" 2019 32 "old"   "British Columbia-old"   0 1 0  28271 1 0 1
     90 "British Columbia" 2018 50 "old"   "British Columbia-old"   1 1 1   6557 0 1 1
     91 "Quebec"           2019 46 "old"   "Quebec-old"             1 1 0  75666 0 0 1
     92 "Quebec"           2018 45 "old"   "Quebec-old"             1 0 1 141008 1 0 1
     93 "Quebec"           2017 34 "old"   "Quebec-old"             1 1 1  26363 1 0 0
     94 "Quebec"           2019 26 "old"   "Quebec-old"             1 0 1  70991 1 1 1
     95 "Quebec"           2018 36 "old"   "Quebec-old"             1 0 1 104035 1 1 0
     96 "Quebec"           2017 38 "old"   "Quebec-old"             1 1 1  77509 0 0 1
     97 "Quebec"           2017 17 "young" "Quebec-young"           0 1 1  71834 1 0 0
     98 "Quebec"           2020 12 "young" "Quebec-young"           1 0 0   9244 1 0 1
     99 "Quebec"           2019 14 "young" "Quebec-young"           1 1 1 135374 1 0 0
    100 "Quebec"           2017 48 "old"   "Quebec-old"             1 0 0  34177 0 1 1
    end
    My current code is this:
    Code:
    local if_list `" "if year != ." "if prov == "Ontario"  "'
    
    foreach cond in `if_list' {
        reg satisfied good_health `cond'
    }
    However, I get the following error message: "{ required
    r(100);"

    Could someone please help me resolve this issue?

    Thanks!

  • #2
    (I have more than two conditions I actually want to loop over, I just simplified things for the purposes of this example.)

    Comment


    • #3
      I'm not exactly sure why you are getting that error message but if you replace your -foreach- line with the following, it works:
      Code:
      foreach ln of local if_list {
      added in edit: well, it runs, but I'm not sure it's what you want

      Comment


      • #4
        Thanks Rich, but that didn't work for me unfortunately:

        [CODE]
        foreach ln of local if_list {
        reg satisfied treatment `ln'
        }
        [\CODE]

        only runs the first regression and then says "invalid syntax".

        Comment


        • #5
          Your list is not balanced. Parse it thus

          Code:
          `"  
          
          "if year != ."  
          
          "if prov == "Ontario"    
          
          "'
          The second qualifier needs outermost quotation marks, namely

          Code:
          `" if prov == "Ontario" "'
          I have to wonder whether you are making your code less readable, harder to maintain and harder to debug, and indeed the question is evidence for that.
          Last edited by Nick Cox; 08 Feb 2023, 15:49.

          Comment


          • #6
            Thanks Nick. Unfortunately, this seems to only run the regression for the first condition and then gives an "invalid syntax...r(198)" error when I try to condition on the province being Ontario.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input byte id str16 prov int year byte age str5 age_gp str22 prov_age_gp byte(female immigrant white) long income byte(hs satisfied good_health)
              1 "Ontario"          2014 33 "old"   "Ontario-old"            1 0 1 100407 0 1 1
              2 "Ontario"          2020 27 "old"   "Ontario-old"            0 1 1  74657 1 1 1
              3 "Ontario"          2020 45 "old"   "Ontario-old"            0 1 1  83161 0 1 0
              4 "Ontario"          2020 23 "young" "Ontario-young"          1 1 1  75722 1 0 1
              5 "Ontario"          2020 50 "old"   "Ontario-old"            0 1 1  57515 0 0 1
              6 "Ontario"          2014 12 "young" "Ontario-young"          0 1 1 116117 0 1 0
              7 "Ontario"          2018 23 "young" "Ontario-young"          0 1 0  92396 1 0 1
              8 "Ontario"          2017 14 "young" "Ontario-young"          1 0 0  31846 1 1 0
              9 "Ontario"          2018 13 "young" "Ontario-young"          1 1 1  97230 0 1 0
             10 "Ontario"          2016 29 "old"   "Ontario-old"            1 1 0 146051 0 1 1
             11 "Ontario"          2015 12 "young" "Ontario-young"          1 1 0  39582 1 1 0
             12 "Ontario"          2016 28 "old"   "Ontario-old"            1 0 1 115098 1 1 0
             13 "Ontario"          2020 39 "old"   "Ontario-old"            0 0 0  69452 0 0 0
             14 "Ontario"          2017 19 "young" "Ontario-young"          1 1 1  46980 0 1 0
             15 "Ontario"          2014 32 "old"   "Ontario-old"            1 1 0  86176 0 0 1
             16 "Ontario"          2018 19 "young" "Ontario-young"          0 1 0 136418 0 0 0
             17 "Ontario"          2016 48 "old"   "Ontario-old"            0 1 0   2678 0 0 0
             18 "Ontario"          2014 21 "young" "Ontario-young"          0 0 0  93515 1 0 1
             19 "Ontario"          2019 31 "old"   "Ontario-old"            1 1 1  47945 1 1 1
             20 "Ontario"          2016 24 "young" "Ontario-young"          0 1 0  38551 0 1 1
             21 "Ontario"          2015 20 "young" "Ontario-young"          0 1 1  27645 1 1 1
             22 "Ontario"          2019 46 "old"   "Ontario-old"            0 1 1  62639 0 1 1
             23 "Ontario"          2017 46 "old"   "Ontario-old"            1 1 0 130286 1 1 0
             24 "Ontario"          2018 38 "old"   "Ontario-old"            0 1 1  52823 0 0 0
             25 "Ontario"          2016 41 "old"   "Ontario-old"            0 1 0 148866 1 0 0
             26 "Ontario"          2014 41 "old"   "Ontario-old"            0 0 1  42689 1 1 0
             27 "Ontario"          2016 30 "old"   "Ontario-old"            1 1 1  26349 1 0 1
             28 "Ontario"          2014 50 "old"   "Ontario-old"            1 0 1 146965 1 1 0
             29 "Ontario"          2017 33 "old"   "Ontario-old"            0 0 1 144849 0 1 0
             30 "Ontario"          2020 36 "old"   "Ontario-old"            0 0 0  44745 1 1 1
             31 "Ontario"          2018 15 "young" "Ontario-young"          0 0 1  36163 0 1 0
             32 "Ontario"          2015 47 "old"   "Ontario-old"            1 0 0  87398 0 0 1
             33 "Ontario"          2017 23 "young" "Ontario-young"          0 0 1  87833 0 1 0
             34 "Ontario"          2015 31 "old"   "Ontario-old"            0 1 0  19675 0 0 1
             35 "Ontario"          2016 25 "old"   "Ontario-old"            0 0 1 141300 0 1 0
             36 "Ontario"          2014 39 "old"   "Ontario-old"            0 1 0  95323 1 1 1
             37 "Ontario"          2018 17 "young" "Ontario-young"          1 1 1  26585 0 0 0
             38 "Ontario"          2018 29 "old"   "Ontario-old"            1 0 1 110093 1 1 1
             39 "Ontario"          2019 21 "young" "Ontario-young"          1 0 0  48938 1 0 1
             40 "Ontario"          2015 45 "old"   "Ontario-old"            0 0 0 106064 1 0 1
             41 "Ontario"          2015 38 "old"   "Ontario-old"            0 0 1 113473 0 0 0
             42 "Ontario"          2019 42 "old"   "Ontario-old"            0 0 0  43939 0 0 0
             43 "Ontario"          2017 41 "old"   "Ontario-old"            1 1 1 133062 1 1 1
             44 "Ontario"          2019 32 "old"   "Ontario-old"            0 0 1 126149 1 0 1
             45 "Ontario"          2015 46 "old"   "Ontario-old"            1 0 1 137881 0 1 1
             46 "Ontario"          2015 31 "old"   "Ontario-old"            1 1 0 123258 0 1 0
             47 "Ontario"          2020 20 "young" "Ontario-young"          0 1 1  75791 1 1 0
             48 "Ontario"          2016 45 "old"   "Ontario-old"            1 1 1 112068 1 1 1
             49 "Ontario"          2016 23 "young" "Ontario-young"          1 0 1  51956 0 0 1
             50 "Ontario"          2016 20 "young" "Ontario-young"          0 0 1   6505 1 0 0
             51 "Alberta"          2018 47 "old"   "Alberta-old"            0 0 1    568 0 1 0
             52 "Alberta"          2017 34 "old"   "Alberta-old"            1 0 0    439 1 1 0
             53 "Alberta"          2020 26 "old"   "Alberta-old"            1 0 0 115646 0 0 1
             54 "Alberta"          2014 41 "old"   "Alberta-old"            0 0 0  48910 1 1 0
             55 "Alberta"          2016 36 "old"   "Alberta-old"            0 0 1 102959 0 1 1
             56 "Alberta"          2019 45 "old"   "Alberta-old"            1 1 0  25057 1 1 0
             57 "Alberta"          2016 36 "old"   "Alberta-old"            1 1 1 114133 1 1 1
             58 "Alberta"          2015 30 "old"   "Alberta-old"            0 1 1 111965 1 1 1
             59 "Alberta"          2016 18 "young" "Alberta-young"          0 1 1 142191 0 0 0
             60 "Alberta"          2015 41 "old"   "Alberta-old"            0 0 0  40717 0 1 0
             61 "Alberta"          2014 41 "old"   "Alberta-old"            0 0 0 101012 1 1 1
             62 "Alberta"          2018 19 "young" "Alberta-young"          1 0 0 127749 0 0 1
             63 "Alberta"          2017 46 "old"   "Alberta-old"            1 0 0  48383 0 0 0
             64 "Alberta"          2014 31 "old"   "Alberta-old"            0 1 1  41787 1 1 0
             65 "Alberta"          2014 48 "old"   "Alberta-old"            1 0 0  77192 1 0 1
             66 "Alberta"          2017 21 "young" "Alberta-young"          1 0 0  87067 1 1 0
             67 "Alberta"          2015 13 "young" "Alberta-young"          0 0 0  16935 1 1 0
             68 "Alberta"          2017 17 "young" "Alberta-young"          1 1 1 110079 0 1 1
             69 "Alberta"          2015 18 "young" "Alberta-young"          0 0 1  43234 0 1 1
             70 "Alberta"          2015 45 "old"   "Alberta-old"            1 1 0    861 0 0 1
             71 "Alberta"          2015 32 "old"   "Alberta-old"            0 1 1  32675 1 0 1
             72 "British Columbia" 2014 22 "young" "British Columbia-young" 0 1 0 126936 1 1 0
             73 "British Columbia" 2019 19 "young" "British Columbia-young" 1 0 0  18763 0 0 0
             74 "British Columbia" 2020 13 "young" "British Columbia-young" 1 0 0  78998 1 1 1
             75 "British Columbia" 2015 37 "old"   "British Columbia-old"   0 0 1  76340 0 1 0
             76 "British Columbia" 2018 35 "old"   "British Columbia-old"   1 1 1  75289 0 0 0
             77 "British Columbia" 2019 26 "old"   "British Columbia-old"   1 1 0   4810 0 0 1
             78 "British Columbia" 2020 41 "old"   "British Columbia-old"   1 1 1 142516 1 1 0
             79 "British Columbia" 2015 35 "old"   "British Columbia-old"   0 1 0 105552 1 1 1
             80 "British Columbia" 2015 12 "young" "British Columbia-young" 0 0 1 129348 0 0 0
             81 "British Columbia" 2015 46 "old"   "British Columbia-old"   0 1 0  78976 0 0 0
             82 "British Columbia" 2016 46 "old"   "British Columbia-old"   0 1 0  73313 1 0 1
             83 "British Columbia" 2014 26 "old"   "British Columbia-old"   0 0 1 110565 1 1 0
             84 "British Columbia" 2016 17 "young" "British Columbia-young" 1 1 1  54889 1 1 0
             85 "British Columbia" 2016 21 "young" "British Columbia-young" 0 1 0 146396 1 0 1
             86 "British Columbia" 2020 16 "young" "British Columbia-young" 0 1 1  20529 0 0 1
             87 "British Columbia" 2017 23 "young" "British Columbia-young" 0 1 1  95769 1 0 0
             88 "British Columbia" 2016 19 "young" "British Columbia-young" 1 0 1  86253 0 1 0
             89 "British Columbia" 2019 32 "old"   "British Columbia-old"   0 1 0  28271 1 0 1
             90 "British Columbia" 2018 50 "old"   "British Columbia-old"   1 1 1   6557 0 1 1
             91 "Quebec"           2019 46 "old"   "Quebec-old"             1 1 0  75666 0 0 1
             92 "Quebec"           2018 45 "old"   "Quebec-old"             1 0 1 141008 1 0 1
             93 "Quebec"           2017 34 "old"   "Quebec-old"             1 1 1  26363 1 0 0
             94 "Quebec"           2019 26 "old"   "Quebec-old"             1 0 1  70991 1 1 1
             95 "Quebec"           2018 36 "old"   "Quebec-old"             1 0 1 104035 1 1 0
             96 "Quebec"           2017 38 "old"   "Quebec-old"             1 1 1  77509 0 0 1
             97 "Quebec"           2017 17 "young" "Quebec-young"           0 1 1  71834 1 0 0
             98 "Quebec"           2020 12 "young" "Quebec-young"           1 0 0   9244 1 0 1
             99 "Quebec"           2019 14 "young" "Quebec-young"           1 1 1 135374 1 0 0
            100 "Quebec"           2017 48 "old"   "Quebec-old"             1 0 0  34177 0 1 1
            end
            
            
            local if_list `"   " if year != . "   " if prov == "Ontario" "    "'
            
            foreach cond in `if_list' {
                reg satisfied good_health `cond'
            }

            Comment


            • #7
              You didn't do as I suggested. Given the use of double quotation marks around Ontario, you need compound double quotation marks around the qualifier.

              (I edited my code belatedly just a few minutes ago and it may not have been clear enough first time round. Sorry about that. But if a further edit doesn't work, it is yet more evidence that this route up the mountain is too much like hard work.)

              Comment


              • #8
                Debugging problems like this requires using the macro list command to see exactly what the local macros resolve to.
                Code:
                . local if_list `"   " if year != . "   " if prov == "Ontario" "    "'
                
                . macro list _if_list
                _if_list:        " if year != . " " if prov == "Ontario" "
                
                .
                . foreach cond in `if_list' {
                  2.     capture noisily macro list _cond
                  3. }
                _cond:           if year != .
                _cond:           if prov ==
                _cond:          Ontario"
                local macro `cond' not found
                
                .
                . local if_list `"   " if year != . "   `" if prov == "Ontario" "'    "'
                
                . macro list _if_list
                _if_list:        " if year != . " `" if prov == "Ontario" "'
                
                .
                . foreach cond in `if_list' {
                  2.     capture noisily macro list _cond
                  3. }
                _cond:           if year != .
                _cond:           if prov == "Ontario"
                
                .

                Comment


                • #9
                  Because the use of quotation marks gets a bit tricky in situations like this, I use a different approach:

                  Code:
                  local condition1 if year != .
                  local condition2 if prov == "Ontario"
                  
                  forvalues i = 1/2 {   
                      reg satisfied good_health `condition`i''
                  }
                  While this is a little bit more typing, it is easier typing and there is much less risk of getting tripped up by quotation marks.

                  That said, if you are going to do something like this, I strongly recommend that in your loop you include a -display- command that writes out the regression command ahead of each regression. Otherwise you are going to end up with a long series of regression tables one after the other, and except perhaps the first and last it will be nearly impossible to know which is which. Skipping a few lines between regressions would also make the output easier on the eye.

                  Comment


                  • #10
                    Thanks all! This was very helpful.

                    Clyde, thanks for sharing your approach, this seems like a much better way to do things. I will also heed your advice to display the regression command.

                    Comment


                    • #11
                      A little trick to help with Clyde's last paragraph is that most (all?) estimation commands have a returned macro showing the translated command that was used, -e(cmdline)-. It will capture any if/in conditions and options as well. You can print this out immediately after your command as well to document what you did.

                      Comment

                      Working...
                      X