Announcement

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

  • Results from a loop with quarterly and weekly data are different in relation to the sort of data: What is happening here?

    Hi

    I have a dataset that includes a quarterly_macro variable which is the same for each week of the quarter and weekly variables (i.e., the macro variable of quarter Q is linked to weeks from 1-12 of quarter Q).

    I want to fit a model on a sample and test its performance out-of-sample. My problem is as follows:

    When I run the same loop on my data, it produces different results conditional on the -sort- I use. I am not sure what does the -sort- exactly mean in each case. I elaborate below.


    First alternative:
    Code:
    frames reset
    
    use quarterly_weekly.dta, clear
    
    
    // The issue is here:
    sort  quarter_date myWEEK // this sort changes the result
    
    
    gen SUBsample=.
    replace SUBsample=1 if quarter_date<tq(1999q4)  // a sample to fit the model
    replace SUBsample=2  if SUBsample==.   // a sample to evaluate the model (out of sample)
    
    
    gen prediction=.
    
    set seed 12345 // this is done for the results to be reproducible 
    
    levelsof myWEEK, local(levels)
    
    foreach x of local levels {
      
    lasso linear quarterly_macro weekly_var1-weekly_var30 if SUBsample == 1 
    estimates store LASSOrev 
    predict temp if SUBsample==2 & myWEEK==`x', postselection
    replace prediction=temp  if myWEEK==`x'
    drop temp
    }
    The data according to this sort look like this:

    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(quarter_date myWEEK quarterly_macro) double(weekly_var1 weekly_var2)
    88 1 .234 .10359720885753632 .8679591417312622
    88 2 .234 .1684819906949997 .6942142844200134
    88 3 .234 .1135205626487732 .78067946434021
    88 4 .234 .1124100349843502 .7621394395828247
    88 5 .234 .11129950731992722 .7485765814781189
    88 6 .234 .12139459326863289 .7513777315616608
    88 7 .234 .12892714142799377 .7541788816452026
    88 8 .234 .1302659884095192 .7332549393177032
    88 9 .234 .12449266016483307 .7331060171127319
    88 10 .234 .12892714142799377 .7332549393177032
    88 11 .234 .13228518515825272 .7331060171127319
    88 12 .234 .13228518515825272 .7365813255310059
    89 1 .442 .07843606919050217 .7152390778064728
    89 2 .442 .08434794098138809 .6936862468719482
    89 3 .442 .1293327808380127 .7534686923027039
    89 4 .442 .1293327808380127 .7293541431427002
    89 5 .442 .1374310553073883 .7074033617973328
    89 6 .442 .135581336915493 .7195637226104736
    89 7 .442 .13115884363651276 .7097733020782471
    89 8 .442 .12929266691207886 .7085883319377899
    89 9 .442 .12363984063267708 .7193162739276886
    89 10 .442 .12925255298614502 .7097733020782471
    89 11 .442 .11802712827920914 .7097733020782471
    89 12 .442 .11715778335928917 .7193162739276886
    90 1 -.027 .05430242419242859 .6410727500915527
    90 2 -.027 .04069159924983978 .6852232813835144
    90 3 -.027 .07825291529297829 .7406743466854095
    90 4 -.027 .0726819857954979 .7218160629272461
    90 5 -.027 .07203014194965363 .7287604510784149
    90 6 -.027 .07235606387257576 .7396003007888794
    90 7 -.027 .07137066125869751 .7391292452812195
    90 8 -.027 .0707111805677414 .7340230643749237
    90 10 -.027 .0707111805677414 .7287604510784149
    90 11 -.027 .0726819857954979 .7287604510784149
    90 12 -.027 .07203014194965363 .7340230643749237
    91 1 1.466 .12981104850769043 .6597848534584045
    91 2 1.466 .09218613058328629 .6661829948425293
    91 3 1.466 .06856242567300797 .6784851551055908
    91 4 1.466 .06452743709087372 .6872596144676208
    91 5 1.466 .052778784185647964 .6839054822921753
    91 6 1.466 .05186103284358978 .6872596144676208
    91 7 1.466 .052778784185647964 .6872596144676208
    91 8 1.466 .0509432815015316 .6872596144676208
    91 9 1.466 .05037875659763813 .6872596144676208
    91 10 1.466 .0509432815015316 .6872596144676208
    91 11 1.466 .05037875659763813 .6872596144676208
    91 12 1.466 .05037875659763813 .6880350112915039

    end
    format %tq quarter_date
    [/CODE]



    Second alternative: // the same code but I only change the sort
    Code:
    frames reset
    
    use quarterly_weekly.dta, clear
    
    
    // The issue is here: THE CHANGE
    sort  myWEEK quarter_date // this sort changes the result
    
    
    gen SUBsample=.
    replace SUBsample=1 if quarter_date<tq(1999q4)  // a sample to fit the model
    replace SUBsample=2  if SUBsample==.   // a sample to evaluate the model (out of sample)
    
    
    gen prediction=.
    
    set seed 12345 // this is done for the results to be reproducible 
    
    levelsof myWEEK, local(levels)
    
    foreach x of local levels {
      
    lasso linear quarterly_macro weekly_var1-weekly_var30 if SUBsample == 1 
    estimates store LASSOrev 
    predict temp if SUBsample==2 & myWEEK==`x', postselection
    replace prediction=temp  if myWEEK==`x'
    drop temp
    }
    The data according to this sort look like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(quarter_date myWEEK quarterly_macro) double(weekly_var1 weekly_var2)
     88 1   .234   .10359720885753632  .8679591417312622
     89 1   .442   .07843606919050217  .7152390778064728
     90 1  -.027   .05430242419242859  .6410727500915527
     91 1  1.466   .12981104850769043  .6597848534584045
     92 1  -.498    .1568187177181244   .752483606338501
     93 1  1.061   .19480887055397034  .6877254247665405
     94 1  -.277  -.22961216419935226  .6739154607057571
     95 1   .533   .20222391188144684  .6799057126045227
     96 1  1.357   .16426868736743927   .607530027627945
     97 1  -.366   .15438511967658997  .6481877565383911
     98 1 -1.091    .5329873561859131  .5102922320365906
     99 1   .326   .36372411251068115    .56190025806427
    100 1 -1.089    .2837163358926773   .749171257019043
    101 1   .146   .10795796103775501  .5764660388231277
    103 1 -1.603   .07519269734621048    .59975266456604
    104 1  -.262   .04535355046391487    .68744957447052
    105 1  -.474 -.061102996580302715     .7769795358181
    106 1   .345  -.03943045064806938  .7835010290145874
    107 1   -.69    .1510646566748619  .7343248724937439
    108 1    .47   .12457912415266037  .8115817308425903
    109 1  -.119   .09771569073200226  .6026725769042969
    110 1    .51  .027549786493182182  .8069815039634705
    111 1   .614   .23088725749403238  .7811554968357086
    112 1  1.348   .06547258608043194  .5904433727264404
    113 1  -.114   .04756193794310093  .6583850979804993
    114 1   .214   .09916634485125542  .8127434849739075
    115 1   .426   .09765896201133728  .6433976590633392
    116 1   -1.1   .18991564214229584  .7861429452896118
    117 1   .851   .07597751915454865   .746464192867279
    118 1   .474   .07555382326245308  .7181055545806885
    119 1    .58   .13181869685649872  .6889693140983582
    120 1  -.234   .17234022915363312  .6527844965457916
    121 1  -.786   .04685705155134201  .7141219973564148
    122 1  -.351   .07157503068447113  .8004719018936157
    123 1   .548   .09237945079803467  .6117232441902161
    124 1   .019  .017031755298376083  .7257599234580994
    125 1  -.921   .09774142131209373  .6640038192272186
    126 1  -.541   .08078432828187943   .650404155254364
    127 1    .14  -.05550992488861084  .6119781732559204
    128 1   .753 -.005241314647719264   .670651912689209
    129 1   .158  .054290205240249634  .6977491974830627
    130 1    .77    .2013719528913498  .6792399883270264
    131 1    .92    .0713081881403923  .5789836049079895
    132 1 -1.068   .06416945718228817  .6183741390705109
    133 1   .319  .038945429027080536  .7245792746543884
    134 1   .024   .18857061862945557  .6980202794075012
    135 1  1.101   .05807130690664053  .5858350396156311
    136 1   .822   .04747616872191429  .5992066860198975
    137 1   .383   .09270800650119781  .6318810880184174
    138 1   .604   .13145361468195915    .71683070063591
    139 1    .54    .1347259134054184   .590053141117096
    140 1   -.12   .16695279628038406  .6224272847175598
    end
    format %tq quarter_date

    I will really appreciate it if someone can explain how the loop estimates the model and then produces the predictions in each case. For example, does it estimate the model on a weekly basis (i.e. does any of these alternatives run the regression for the quarterly dependent variable and week 1 data in SUBsample 1 and then use the parameters to create predictions for week 1 in SUBsample 2 and then do the same thing for each week?)


    I look forward to reading your contributions

    Thanks

  • #2
    Hi All
    I bring this up in case someone can help here.
    the greatest help is to interpret what the change in data sort is actually doing in the loop execution ?!
    Thanks

    Comment


    • #3
      I can't follow all the detail but my guess is that you need to add the "stable" option to your -sort- command; quoting from the help file: "Without the stable option, the ordering of observations with equal
      values of varlist is randomized." see
      Code:
      help sort

      Comment


      • #4
        Thanks.
        As far as I understand from the help file: it is advised to use -sort- without -stable- option when we sort on two variables.


        My interpretation is that when -sort- arranges the data, the loop estimates the model using a sample with a different quarter-week mix. It will help if someone can explain the process that the loop takes to produce "prediction" variable. I had great help from Clyde Schechter in a previous post to construct this https://www.statalist.org/forums/for...-is-very-large

        The issue I am encountering now is that:
        Does the loop estimates the model in SUBsample 1 using all data up to 1999q4 and then these parameters are used to construct predictions using data in SUBsample 2
        OR
        ​​​​​​Does the loop estimates the model in SUBsample 1 using each quarter-week data up to 1999q4 and then the specific quarter-week parameters are used to construct predictions for the same week using data in SUBsample 2

        Comment


        • #5
          I don't really know what is going on here.

          In your example data, the combination of quarter_date and myWEEK uniquely identifies observations. Run -isid quarter_date myWEEK- on your full data set to see if this is also true in your full data set. If so, the sort command will not do anything different if you specify -stable- as the sort order is uniquely determined (though it is a different sort order depending on whether you -sort quarter_date myWEEK- or -sort myWEEK quarter_date-.

          So the question is why that sort order matters to the results you get later. The code contains no -if- condition on the -lasso- estimation, so the entire data set (minus any observations with missing data) is used for the regressions. The -predict- commands are conditioned on the value of myWEEK, but again there is nothing there that looks like it is order dependent.

          I think the mystery lies in the operation of -lasso- itself. It is a partially stochastic procedure. I do not know enough about it to be certain, but I suspect that some of its operations may be sort order dependent, particularly if some data subset is selected based on location in the data set. But I can't say anything more specific than that. Maybe somebody with more than my superficial understanding of -lasso- can give a more specific answer.

          Comment


          • #6
            Thank you so much. Great help.

            I have done two experiments now:
            1- I tried -isid quarter_date myWEEK- and it actually gave me no message at all.
            2- I changed the loop and used old regression -reg- instead of -lasso- and tried both sorts. I found that the results seem to be to be identical under both data sort. So yes Clyde Schechter it seems to be related to the -lasso- command.

            The question remains:

            Does the loop estimates the model in SUBsample 1 using all data up to 1999q4 and then these parameters are used to construct predictions using data in SUBsample 2
            OR
            ​​​​​​Does the loop estimates the model in SUBsample 1 using each quarter-week data up to 1999q4 and then the specific quarter-week parameters are used to construct predictions for the same week using data in SUBsample 2
            I add: As an example for the latter, does it use quarterly_macro with weekly_var1 to weekly_var30 in myWEEK 1 for SUBsample 1 and then use these parameters to generate -prediction- for myWEEK1 in SUBsample 2
            then use quarterly_macro with weekly_var1 to weekly_var30 in myWEEK 2 for SUBsample 1 and then use these parameters to generate -prediction- for myWEEK2 in SUBsample 2
            and so on...

            Look forward to hearing back

            Comment


            • #7
              Does the loop estimates the model in SUBsample 1 using all data up to 1999q4 and then these parameters are used to construct predictions using data in SUBsample 2
              OR
              ​​​​​​Does the loop estimates the model in SUBsample 1 using each quarter-week data up to 1999q4 and then the specific quarter-week parameters are used to construct predictions for the same week using data in SUBsample 2
              The loop uses all data up to 199q4 for the lasso. A single set of parameters is thereby created. Then in subsample 2, those parameters are applied to make predictions for a single quarter-week.

              Comment


              • #8
                Thanks a lot for this:
                The loop uses all data up to 199q4 for the lasso. A single set of parameters is thereby created. Then in subsample 2, those parameters are applied to make predictions for a single quarter-week.
                How can I adjust it to do the following (below)...?
                use quarterly_macro with weekly_var1 to weekly_var30 in myWEEK 1 for SUBsample 1 and then use these parameters to generate -prediction- for myWEEK1 in SUBsample 2
                then use quarterly_macro with weekly_var1 to weekly_var30 in myWEEK 2 for SUBsample 1 and then use these parameters to generate -prediction- for myWEEK2 in SUBsample 2
                and so on...

                Comment


                • #9
                  What are myWEEK1 and myWEEK2? Nothing you have shown so far suggests that there are any such variables in your data set, nor does your loop reference anything related to them.

                  Comment


                  • #10
                    MyWEEK is a week variable that takes the value of 1 to 12 within the quarter. It is one variable so I meant myWEEK==1 , 2, 3, etc. (I am sorry for the confusion). For each "quarter_date", myWEEK will take values from 1 to 12.
                    For example, when the data is sorted as -sort quarter_date myWEEK- it will be as follows:

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input float(quarter_date myWEEK quarterly_macro) double(weekly_var1 weekly_var2)
                    88 1 .234 .10359720885753632 .8679591417312622
                    88 2 .234 .1684819906949997 .6942142844200134
                    88 3 .234 .1135205626487732 .78067946434021
                    88 4 .234 .1124100349843502 .7621394395828247
                    88 5 .234 .11129950731992722 .7485765814781189
                    88 6 .234 .12139459326863289 .7513777315616608
                    88 7 .234 .12892714142799377 .7541788816452026
                    88 8 .234 .1302659884095192 .7332549393177032
                    88 9 .234 .12449266016483307 .7331060171127319
                    88 10 .234 .12892714142799377 .7332549393177032
                    88 11 .234 .13228518515825272 .7331060171127319
                    88 12 .234 .13228518515825272 .7365813255310059
                    89 1 .442 .07843606919050217 .7152390778064728
                    89 2 .442 .08434794098138809 .6936862468719482
                    89 3 .442 .1293327808380127 .7534686923027039
                    89 4 .442 .1293327808380127 .7293541431427002
                    89 5 .442 .1374310553073883 .7074033617973328
                    89 6 .442 .135581336915493 .7195637226104736
                    89 7 .442 .13115884363651276 .7097733020782471
                    89 8 .442 .12929266691207886 .7085883319377899
                    89 9 .442 .12363984063267708 .7193162739276886
                    89 10 .442 .12925255298614502 .7097733020782471
                    89 11 .442 .11802712827920914 .7097733020782471
                    89 12 .442 .11715778335928917 .7193162739276886
                    90 1 -.027 .05430242419242859 .6410727500915527
                    90 2 -.027 .04069159924983978 .6852232813835144
                    90 3 -.027 .07825291529297829 .7406743466854095
                    90 4 -.027 .0726819857954979 .7218160629272461
                    90 5 -.027 .07203014194965363 .7287604510784149
                    90 6 -.027 .07235606387257576 .7396003007888794
                    90 7 -.027 .07137066125869751 .7391292452812195
                    90 8 -.027 .0707111805677414 .7340230643749237
                    90 10 -.027 .0707111805677414 .7287604510784149
                    90 11 -.027 .0726819857954979 .7287604510784149
                    90 12 -.027 .07203014194965363 .7340230643749237
                    91 1 1.466 .12981104850769043 .6597848534584045
                    91 2 1.466 .09218613058328629 .6661829948425293
                    91 3 1.466 .06856242567300797 .6784851551055908
                    91 4 1.466 .06452743709087372 .6872596144676208
                    91 5 1.466 .052778784185647964 .6839054822921753
                    91 6 1.466 .05186103284358978 .6872596144676208
                    91 7 1.466 .052778784185647964 .6872596144676208
                    91 8 1.466 .0509432815015316 .6872596144676208
                    91 9 1.466 .05037875659763813 .6872596144676208
                    91 10 1.466 .0509432815015316 .6872596144676208
                    91 11 1.466 .05037875659763813 .6872596144676208
                    91 12 1.466 .05037875659763813 .6880350112915039
                    
                    end
                    format %tq quarter_date
                    Note that quarterly-macro is the same for a given quarter_date but the var1 to var30 will be different for each myWEEK within the quarter-date. You can think of var1 to var30 as financial variables that are updated each week within the quarter whereas quarterly-macro is for example quarterly GDP growth (var1-var30 are weekly variables whereas quarterly_macro is a quarterly variable).

                    I hope this makes it clear.

                    My aim now is to run the lasso regression using data in SUBsample 1 (which is up till 1999q4) and myWEEK=1 (i.e. the regressions here considers only the weekly variables var1 to var30 as of week 1 of the quarter) and then I multiply the estimated parameters by data in myWEEK=1 SUBsample=2 to make -prediction- for myWEEK=1 out of sample (i.e. the estimates parameters from the regression described here are then multiplied by var1 to var30 as of week 1 in SUBsample 2).
                    Then I repeat the same process for each week. i.e., to run the lasso regression for quarterly data in SUBsample=1 using myWEEK=2 and then I the estimated week-specific parameters will be multiplied by variables in myWEEK=2 in SUBsample=2 to make -prediction- for this week out of sample, and so on.
                    Last edited by Lisa Wilson; 28 Feb 2021, 18:58.

                    Comment


                    • #11
                      Code:
                      levelsof myWEEK, local(levels)
                      gen prediction = .
                      foreach x of local levels {
                          lasso linear quarterly_macro weekly_var1-weekly_var30 if SUBsample == 1 & myWEEK == `x'
                          estimates store LASSOrev
                          predict temp if SUBsample==2 & myWEEK==`x', postselection
                          replace prediction=temp if myWEEK==`x'
                          drop temp
                      }
                      By the way, the -estimates store LASSOrev- command does not really make sense here. At the end of the loop, LASSOrev will only contain the results from the -lasso- in the final iteration of the loop. If you want to stall them all, you have to do so in a separate file for each, so, something like -estimates store LASSOrev`x'-.

                      More generally, when you're in a loop with an index `x', any command that doesn't mention `x' will not distinguish between one value of myWEEK and another. To get results that reflect or are conditioned on the value of myWEEK, you have to explicitly incorporate `x' in the appropriate way into the command.

                      Comment


                      • #12
                        Thank you so much.
                        Unfortunately, I have actually tried the code in #11 before (and did this now again). However, it does not seem to be doing what we have expected.
                        For an unknown reason, it is generating -prediction- that has the same values for all weeks except 2 weeks in each quarter. I copy the results after sorting on quarter_date myWEEK to see the pattern:

                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input float(quarter_date myWEEK prediction)
                        159  1  .1105143
                        159  2 .10566197
                        159  3 .10566197
                        159  4 .10566197
                        159  5 .10566197
                        159  6 .10566197
                        159  7 .10566197
                        159  8 .10566197
                        159  9 .10755715
                        159 10 .10566197
                        159 11 .10566197
                        159 12 .10566197
                        160  1  .1105143
                        160  2 .10566197
                        160  3 .10566197
                        160  4 .10566197
                        160  5 .10566197
                        160  6 .10566197
                        160  7 .10566197
                        160  8 .10566197
                        160  9 .10755715
                        160 10 .10566197
                        160 11 .10566197
                        160 12 .10566197
                        161  1  .1105143
                        161  2 .10566197
                        161  3 .10566197
                        161  4 .10566197
                        161  5 .10566197
                        161  6 .10566197
                        161  7 .10566197
                        161  8 .10566197
                        161  9 .10755715
                        161 10 .10566197
                        161 11 .10566197
                        161 12 .10566197
                        162  1  .1105143
                        162  2 .10566197
                        162  3 .10566197
                        162  4 .10566197
                        162  5 .10566197
                        162  6 .10566197
                        162  7 .10566197
                        162  8 .10566197
                        162  9 .10755715
                        162 10 .10566197
                        162 11 .10566197
                        162 12 .10566197
                        163  1  .1105143
                        163  2 .10566197
                        163  3 .10566197
                        163  4 .10566197
                        163  5 .10566197
                        163  6 .10566197
                        163  7 .10566197
                        163  8 .10566197
                        163  9 .10755715
                        163 10 .10566197
                        163 11 .10566197
                        163 12 .10566197
                        164  1  .1105143
                        164  2 .10566197
                        164  3 .10566197
                        164  4 .10566197
                        164  5 .10566197
                        164  6 .10566197
                        164  7 .10566197
                        164  8 .10566197
                        164  9 .10755715
                        164 10 .10566197
                        164 11 .10566197
                        164 12 .10566197
                        165  1  .1105143
                        165  2 .10566197
                        165  3 .10566197
                        165  4 .10566197
                        165  5 .10566197
                        165  6 .10566197
                        165  7 .10566197
                        165  8 .10566197
                        165  9 .10755715
                        165 10 .10566197
                        165 11 .10566197
                        165 12 .10566197
                        166  1  .1105143
                        166  2 .10566197
                        166  3 .10566197
                        166  4 .10566197
                        166  5 .10566197
                        166  6 .10566197
                        166  7 .10566197
                        166  8 .10566197
                        166  9 .10755715
                        166 10 .10566197
                        166 11 .10566197
                        166 12 .10566197
                        167  1  .1105143
                        167  2 .10566197
                        167  3 .10566197
                        167  4 .10566197
                        end
                        format %tq quarter_date
                        This does not happen when I run the same code exactly as in #11 but without myWEEK=`x' in the second line of the loop. To fix this issue, do you think we can add something that tells Stata that the parameters from the same myWEEK in SUBsample=1 are to be used to make prediction for the same myWEEK in subsample=2 ? If not, can you please let me know how to fix that?

                        Thanks

                        Comment


                        • #13
                          I have attempted to replicate your problem in order to troubleshoot it, but I am not able to do so. I modified things a little: since your example data contains only four quarters, I set the dividing line between SUBsamples 1 and 2 at 1982 q3. Also, to make things simpler, I used -regress- rather than -lasso linear-, and removed the -postselection- option from -predict- (as it is not applicable after -regress-). With these simplifications, the results vary from one value of myWEEK to the next in an expected way:

                          Code:
                          . * Example generated by -dataex-. To install: ssc install dataex
                          . clear
                          
                          . input float(quarter_date myWEEK quarterly_macro) double(weekly_var1 weekly_var2)
                          
                               quarter~e     myWEEK  quarter~o  weekly_v~1  weekly_v~2
                            1. 88 1 .234 .10359720885753632 .8679591417312622
                            2. 88 2 .234 .1684819906949997 .6942142844200134
                            3. 88 3 .234 .1135205626487732 .78067946434021
                            4. 88 4 .234 .1124100349843502 .7621394395828247
                            5. 88 5 .234 .11129950731992722 .7485765814781189
                            6. 88 6 .234 .12139459326863289 .7513777315616608
                            7. 88 7 .234 .12892714142799377 .7541788816452026
                            8. 88 8 .234 .1302659884095192 .7332549393177032
                            9. 88 9 .234 .12449266016483307 .7331060171127319
                           10. 88 10 .234 .12892714142799377 .7332549393177032
                           11. 88 11 .234 .13228518515825272 .7331060171127319
                           12. 88 12 .234 .13228518515825272 .7365813255310059
                           13. 89 1 .442 .07843606919050217 .7152390778064728
                           14. 89 2 .442 .08434794098138809 .6936862468719482
                           15. 89 3 .442 .1293327808380127 .7534686923027039
                           16. 89 4 .442 .1293327808380127 .7293541431427002
                           17. 89 5 .442 .1374310553073883 .7074033617973328
                           18. 89 6 .442 .135581336915493 .7195637226104736
                           19. 89 7 .442 .13115884363651276 .7097733020782471
                           20. 89 8 .442 .12929266691207886 .7085883319377899
                           21. 89 9 .442 .12363984063267708 .7193162739276886
                           22. 89 10 .442 .12925255298614502 .7097733020782471
                           23. 89 11 .442 .11802712827920914 .7097733020782471
                           24. 89 12 .442 .11715778335928917 .7193162739276886
                           25. 90 1 -.027 .05430242419242859 .6410727500915527
                           26. 90 2 -.027 .04069159924983978 .6852232813835144
                           27. 90 3 -.027 .07825291529297829 .7406743466854095
                           28. 90 4 -.027 .0726819857954979 .7218160629272461
                           29. 90 5 -.027 .07203014194965363 .7287604510784149
                           30. 90 6 -.027 .07235606387257576 .7396003007888794
                           31. 90 7 -.027 .07137066125869751 .7391292452812195
                           32. 90 8 -.027 .0707111805677414 .7340230643749237
                           33. 90 10 -.027 .0707111805677414 .7287604510784149
                           34. 90 11 -.027 .0726819857954979 .7287604510784149
                           35. 90 12 -.027 .07203014194965363 .7340230643749237
                           36. 91 1 1.466 .12981104850769043 .6597848534584045
                           37. 91 2 1.466 .09218613058328629 .6661829948425293
                           38. 91 3 1.466 .06856242567300797 .6784851551055908
                           39. 91 4 1.466 .06452743709087372 .6872596144676208
                           40. 91 5 1.466 .052778784185647964 .6839054822921753
                           41. 91 6 1.466 .05186103284358978 .6872596144676208
                           42. 91 7 1.466 .052778784185647964 .6872596144676208
                           43. 91 8 1.466 .0509432815015316 .6872596144676208
                           44. 91 9 1.466 .05037875659763813 .6872596144676208
                           45. 91 10 1.466 .0509432815015316 .6872596144676208
                           46. 91 11 1.466 .05037875659763813 .6872596144676208
                           47. 91 12 1.466 .05037875659763813 .6880350112915039
                           48.
                          . end
                          
                          . format %tq quarter_date
                          
                          .
                          . gen SUBsample=.
                          (47 missing values generated)
                          
                          . replace SUBsample=1 if quarter_date<tq(1982q3)  // a sample to fit the model
                          (24 real changes made)
                          
                          . replace SUBsample=2  if SUBsample==.   // a sample to evaluate the model (out of sample)
                          (23 real changes made)
                          
                          .
                          .
                          . levelsof myWEEK, local(levels)
                          1 2 3 4 5 6 7 8 9 10 11 12
                          
                          . gen prediction = .
                          (47 missing values generated)
                          
                          . foreach x of local levels {
                            2.     regress quarterly_macro weekly_var1-weekly_var2 if SUBsample == 1 & myWEEK == `x'
                            3.     estimates store LASSOrev
                            4.     predict temp if SUBsample==2 & myWEEK==`x'
                            5.     replace prediction=temp if myWEEK==`x'
                            6.     drop temp
                            7. }
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -1.361969          .        .       .            .           .
                                 _cons |   1.416134          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var2 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |  -2.472245          .        .       .            .           .
                           weekly_var2 |          0  (omitted)
                                 _cons |   .6505288          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -7.644032          .        .       .            .           .
                                 _cons |   6.201539          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -6.344308          .        .       .            .           .
                                 _cons |   5.069247          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -5.051828          .        .       .            .           .
                                 _cons |    4.01568          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |     -6.538          .        .       .            .           .
                                 _cons |   5.146508          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -4.684096          .        .       .            .           .
                                 _cons |   3.766646          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -8.432453          .        .       .            .           .
                                 _cons |   6.417138          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -15.08367          .        .       .            .           .
                                 _cons |   11.29193          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (46 missing values generated)
                          (1 real change made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -8.857986          .        .       .            .           .
                                 _cons |   6.729162          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -8.914522          .        .       .            .           .
                                 _cons |    6.76929          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          note: weekly_var1 omitted because of collinearity
                          
                                Source |       SS           df       MS      Number of obs   =         2
                          -------------+----------------------------------   F(1, 0)         =         .
                                 Model |  .021632001         1  .021632001   Prob > F        =         .
                              Residual |           0         0           .   R-squared       =    1.0000
                          -------------+----------------------------------   Adj R-squared   =         .
                                 Total |  .021632001         1  .021632001   Root MSE        =         0
                          
                          ------------------------------------------------------------------------------
                          quarterly_~o |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                           weekly_var1 |          0  (omitted)
                           weekly_var2 |  -12.04746          .        .       .            .           .
                                 _cons |   9.107933          .        .       .            .           .
                          ------------------------------------------------------------------------------
                          (option xb assumed; fitted values)
                          (45 missing values generated)
                          (2 real changes made)
                          
                          .
                          . list, noobs clean
                          
                              quarte~e   myWEEK   quarte~o   weekly_~1   weekly_~2   SUBsam~e   predic~n   _est_L~v  
                                1982q1        1       .234   .10359721   .86795914          1          .          0  
                                1982q1        2       .234   .16848199   .69421428          1          .          0  
                                1982q1        3       .234   .11352056   .78067946          1          .          0  
                                1982q1        4       .234   .11241003   .76213944          1          .          0  
                                1982q1        5       .234   .11129951   .74857658          1          .          0  
                                1982q1        6       .234   .12139459   .75137773          1          .          0  
                                1982q1        7       .234   .12892714   .75417888          1          .          0  
                                1982q1        8       .234   .13026599   .73325494          1          .          0  
                                1982q1        9       .234   .12449266   .73310602          1          .          0  
                                1982q1       10       .234   .12892714   .73325494          1          .          0  
                                1982q1       11       .234   .13228519   .73310602          1          .          0  
                                1982q1       12       .234   .13228519   .73658133          1          .          1  
                                1982q2        1       .442   .07843607   .71523908          1          .          0  
                                1982q2        2       .442   .08434794   .69368625          1          .          0  
                                1982q2        3       .442   .12933278   .75346869          1          .          0  
                                1982q2        4       .442   .12933278   .72935414          1          .          0  
                                1982q2        5       .442   .13743106   .70740336          1          .          0  
                                1982q2        6       .442   .13558134   .71956372          1          .          0  
                                1982q2        7       .442   .13115884    .7097733          1          .          0  
                                1982q2        8       .442   .12929267   .70858833          1          .          0  
                                1982q2        9       .442   .12363984   .71931627          1          .          0  
                                1982q2       10       .442   .12925255    .7097733          1          .          0  
                                1982q2       11       .442   .11802713    .7097733          1          .          0  
                                1982q2       12       .442   .11715778   .71931627          1          .          1  
                                1982q3        1      -.027   .05430242   .64107275          2   .5430123          0  
                                1982q3        2      -.027    .0406916   .68522328          2   .5499292          0  
                                1982q3        3      -.027   .07825292   .74067435          2   .5398004          0  
                                1982q3        4      -.027   .07268199   .72181606          2   .4898239          0  
                                1982q3        5      -.027   .07203014   .72876045          2   .3341077          0  
                                1982q3        6      -.027   .07235606    .7396003          2   .3110009          0  
                                1982q3        7      -.027   .07137066   .73912925          2   .3044939          0  
                                1982q3        8      -.027   .07071118   .73402306          2   .2275228          0  
                                1982q3       10      -.027   .07071118   .72876045          2   .2738121          0  
                                1982q3       11      -.027   .07268199   .72876045          2   .2727386          0  
                                1982q3       12      -.027   .07203014   .73402306          2   .2648205          0  
                                1982q4        1      1.466   .12981105   .65978485          2   .5175269          0  
                                1982q4        2      1.466   .09218613   .66618299          2   .4226221          0  
                                1982q4        3      1.466   .06856243   .67848516          2   1.015177          0  
                                1982q4        4      1.466   .06452744   .68725961          2   .7090606          0  
                                1982q4        5      1.466   .05277878   .68390548          2   .5607072          0  
                                1982q4        6      1.466   .05186103   .68725961          2   .6532043          0  
                                1982q4        7      1.466   .05277878   .68725961          2   .5474563          0  
                                1982q4        8      1.466   .05094328   .68725961          2   .6218534          0  
                                1982q4        9      1.466   .05037876   .68725961          2   .9255322          0  
                                1982q4       10      1.466   .05094328   .68725961          2   .6414259          0  
                                1982q4       11      1.466   .05037876   .68725961          2   .6426988          0  
                                1982q4       12      1.466   .05037876   .68803501          2   .8188598          0
                          It is possible that the problem is something to do with -lasso-, though I find it hard to think of any reason that should be the case. Anyway, the above demonstrates that the logic of the loop and the use of -myWEEK == `x'- is, in principle correct.

                          I suspect that what you are actually running is somehow different. I think for additional help you will have to post a new set of example data that reproduces your problem, along with the exact code that is giving rise to the problem.

                          Comment


                          • #14
                            I have now tried to run the same code but using OLS regression rather than a lasso and it turns out that -prediction- will vary throughout the quarter in SUBsample=2

                            The code is as follows

                            Code:
                            use macro_financial.dta, clear
                            
                            sort  quarter_date myWEEK // this sort is important 
                            
                            gen SUBsample=.
                            replace SUBsample=1 if quarter_date<tq(1999q4)  // a sample to fit the model
                            replace SUBsample=2  if SUBsample==. 
                            
                            levelsof myWEEK, local(levels)
                            gen prediction = .
                            foreach x of local levels {
                                reg quarterly_macro var1-var30 if SUBsample == 1 & myWEEK == `x'
                                predict temp if SUBsample==2 & myWEEK==`x'
                                replace prediction=temp if myWEEK==`x'
                                drop temp
                            }
                            See this:

                            dataex quarter_date myWEEK var1-var4 prediction if prediction!=.

                            Code:
                            * Example generated by -dataex-. To install: ssc install dataex
                            clear
                            input float(quarter_date myWEEK) double(var1 var2 var3 var4) float prediction
                            159  1  .17202481627464294 .6948989629745483 0  .1255931258201599    -.367004
                            159  2  .08726572245359421 .5852832198143005 0 .16591352224349976     .606835
                            159  3  .08755961060523987 .6146115064620972 0 .16698487102985382   .19753617
                            159  4  .09736887365579605 .6271798312664032 0 .15359827876091003    .4616309
                            159  5  .09771715849637985 .6332393884658813 0 .15471814572811127    .5379525
                            159  6  .09684964641928673 .6422252655029297 0  .1548289805650711    .4940058
                            159  7  .09132839739322662 .6490611433982849 0   .151839017868042    .2302138
                            159  8   .0920257456600666   .64776611328125 0  .1522219479084015    .2442109
                            159  9  .09288154542446136 .6490147709846497 0 .15121181309223175    .2833941
                            159 10  .09267959371209145 .6491391658782959 0 .15094389766454697    .4998643
                            159 11  .09368276596069336 .6491060256958008 0 .15257544815540314   .27623725
                            159 12  .09348877519369125  .649423360824585 0 .15257832407951355   .27601817
                            160  1  .17111922800540924 .6154264211654663 0 .23937074840068817  -.18413717
                            160  2  .13095935434103012 .5739885866641998 0 .20118161290884018    .3167815
                            160  3   .1158703863620758 .5563300251960754 0 .19108844548463821   -.3515978
                            160  4  .11729777604341507 .6049938499927521 0  .1627333015203476    .5479197
                            160  5  .11438766121864319 .6195304691791534 0 .15628818422555923    .4298742
                            160  6   .1086440458893776 .6352617740631104 0 .15361635386943817    .3486477
                            160  7  .11149692162871361  .636299729347229 0  .1583489328622818   -.3276848
                            160  8  .11721164733171463 .6439498364925385 0  .1583489328622818  -.08620454
                            160  9  .11440581828355789 .6494276523590088 0 .16035141050815582   -.4241118
                            160 10  .11200645938515663 .6503129601478577 0 .16148623824119568   .12204248
                            160 11  .10810811072587967  .653168797492981 0 .16246066987514496   .14565541
                            160 12  .10642673820257187 .6584376096725464 0 .15670017153024673  -.17241064
                            161  1  .14491452276706696 .6484046578407288 0 .15475750714540482   -.1980061
                            161  2  .12961874902248383 .5994188189506531 0 .18819470703601837    .3479501
                            161  3  .13077442348003387 .6243222951889038 0 .16704648733139038   .14257655
                            161  4  .13560082763433456 .6291109919548035 0  .1585458591580391   1.0919781
                            161  5    .134987473487854 .6393308639526367 0  .1601102650165558    1.533112
                            161  6  .13079164922237396 .6464573442935944 0  .1562201976776123    .5786533
                            161  7   .1272428333759308 .6527997851371765 0 .15556050837039948   .29579476
                            161  8  .12636715173721313 .6527997851371765 0  .1562201976776123    .2353444
                            161  9  .12671452015638351 .6548358201980591 0 .15631398558616638   .11923996
                            161 10  .12671452015638351 .6540347337722778 0 .15780232846736908    .7721721
                            161 11  .12645623087882996 .6571459770202637 0 .15653607994318008    .6862189
                            161 12  .12645623087882996 .6561213135719299 0  .1573871150612831   .52644956
                            162  1   .1797257661819458 .6371322274208069 0 .17580880969762802  -1.2724226
                            162  2  .13075383007526398 .5806174874305725 0 .17817559838294983   1.2617252
                            162  3  .13349992036819458  .609599769115448 0  .1678634062409401 -.017566996
                            162  4  .13940788060426712 .6268700063228607 0 .14918746799230576    .9494944
                            162  5  .13891521096229553 .6297124624252319 0 .15305207669734955   1.4321374
                            162  6  .13665823638439178 .6481447219848633 0  .1425313502550125   .54888177
                            162  7  .13349992036819458 .6515621542930603 0 .14820554107427597    .3511284
                            162  8  .13342637568712235  .651780366897583 0 .14843717217445374    .4125963
                            162  9   .1333746314048767 .6511694490909576 0  .1494891345500946   .19251144
                            162 10  .13281245529651642 .6511694490909576 0 .15040342509746552    .6310902
                            162 11  .13180480897426605 .6513743698596954 0 .15074290335178375   .50450313
                            162 12  .13075383007526398 .6515640020370483 0 .15074290335178375    .5405798
                            163  1  .13142557442188263 .6350573897361755 0 .09678983688354492   -.7517709
                            163  2  .13142557442188263 .5912758708000183 0  .1719038337469101   .28171816
                            163  3  .12786316126585007 .6035119295120239 0 .16719773411750793   .04807652
                            163  4   .1295439824461937 .6323953866958618 0  .1513693630695343   1.2039424
                            163  5  .12778769433498383 .6365582942962646 0 .15163849294185638   1.5949997
                            163  6  .12600279599428177 .6548150181770325 0 .14497928321361542    .5887893
                            163  7   .1244606263935566 .6533806025981903 0 .15005149692296982   .47324705
                            163  8  .12600279599428177 .6563734412193298 0 .14977477490901947    .6470234
                            163  9   .1235642209649086 .6584279239177704 0 .15011686086654663    .4616888
                            163 10   .1244606263935566 .6572011709213257 0 .15104155987501144    .6006604
                            163 11  .12304829806089401 .6584279239177704 0 .15110023319721222    .7408893
                            163 12  .12192801386117935 .6592446267604828 0 .15110023319721222    .7045531
                            164  1  .20648633688688278 .6599540114402771 0 .20093418657779694   -.2107001
                            164  2    .137313112616539 .6277409791946411 0 .20318245142698288    .3074275
                            164  3  .13510505855083466 .5473548769950867 0 .18720874190330505   -.0977029
                            164  4  .12848623096942902 .6149873733520508 0 .15401911735534668   1.0619364
                            164  5   .1237865537405014 .6250452995300293 0 .15281912684440613    .9641484
                            164  6  .11706551536917686  .635746419429779 0 .15401911735534668    .4841817
                            164  7   .1150100976228714 .6400367617607117 0 .15568794310092926  -.06540407
                            164  8   .1162869818508625 .6460942029953003 0 .15538296103477478    .3801022
                            164  9  .11454347148537636 .6488784551620483 0  .1582978218793869  .014257866
                            164 10  .11386915296316147 .6493513882160187 0  .1584063172340393    .4596438
                            164 11  .11291179433465004 .6501693725585938 0 .15945643186569214     .626457
                            164 12  .11227846890687943  .654008537530899 0  .1574791967868805    .1576482
                            165  1  .07610215991735458 .6751998960971832 0  .2197740077972412   -.5693078
                            165  2  .08361964672803879 .5880566239356995 0 .21392622590065002    .3125312
                            165  3  .08247310668230057 .6171504259109497 0 .19207023084163666   .19541962
                            165  4   .0879647359251976 .6265825629234314 0 .17705722153186798     .881165
                            165  5  .08523021638393402 .6360268592834473 0 .17160910367965698   .52674335
                            165  6   .0880705788731575 .6372712850570679 0 .17004688829183578    .3252075
                            165  7  .08525755256414413 .6513693332672119 0 .16902992129325867  -.20680957
                            165  8  .08312014490365982 .6520046889781952 0 .17108294367790222  -.10045855
                            165  9  .08258269354701042 .6525267958641052 0 .17042916268110275   -.4694794
                            165 10  .08257213979959488 .6529653072357178 0 .17108294367790222   .10559583
                            165 11  .08105259016156197 .6525267958641052 0 .17185808718204498    .1717396
                            165 12   .0800948366522789 .6535940170288086 0 .17136012017726898   .16738266
                            166  1  .05268929526209831 .5510042309761047 0  .2525259852409363  -.06225803
                            166  2   .0794920027256012 .5104886293411255 0 .22708429396152496   1.1651896
                            166  3  .04082721099257469 .5796815752983093 0 .19367379695177078  -.12041347
                            166  4 .042941637337207794  .619637131690979 0 .17618374526500702    .4961323
                            166  5  .04234897531569004 .6262461841106415 0  .1691722795367241   .35703275
                            166  6  .04082237929105759  .634378969669342 0 .16467291861772537    .1134478
                            166  7  .04548211023211479 .6370747089385986 0  .1670393943786621   -.4081667
                            166  8 .042941637337207794 .6387808918952942 0  .1696765422821045  -.25494948
                            166  9 .043411120772361755 .6387808918952942 0  .1696765422821045   -.5004613
                            166 10  .04170646145939827 .6389527916908264 0 .17012599110603333    -.182741
                            166 11  .04148177616298199 .6388466954231262 0 .17207148671150208    -.374203
                            166 12 .042254675179719925 .6390860676765442 0   .172869473695755   -.1125627
                            167  1  .04285532049834728 .6148322224617004 0 .16688518226146698   -.3951057
                            167  2 .043713899329304695 .5703524351119995 0 .21236152946949005     .353757
                            167  3 .011709208600223064 .5882739424705505 0  .1973503977060318    .2114365
                            167  4 .009011868387460709 .6290616989135742 0 .18054378777742386    .6421046
                            end
                            format %tq quarter_date

                            This probably indicates that it is something specific to the way we used the lasso in the loop. For some reason, using lasso with - if myWEEK==`x' - does something to the execution of the loop which is not apparent when we use -reg-


                            I look forward to hearing back. Let me know if I should send any more data.

                            Comment


                            • #15
                              Please post back with the exact code you are using, including: the creation of the SUBsample variable and everything that happens from there through the entire loop containing the -lasso- command, and example data that is sufficiently large that the code you show will run on it and will reproduce the difficulties you are encountering.

                              Comment

                              Working...
                              X