Announcement

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

  • Appending regressions

    I am attempting to regress every 6 months, then append these regressions to form a single index from 2004-2018. However, I am getting the mismatch error-

    Code:
    . foreach var of varlist ldiffcost_w_res -ldiffexpense_w_res {
      2. regress `var' rmrf, robust
      3. if date >= "01-01-2004" & date <= "06-30-2004"
      4.     if e(b)[1,1] < 0 local negvars `negvars' `var'
      5. egen UKIS1 = rowmean(`negvars')
      6. save UKIS1, replace
      7. }
    
    Linear regression                               Number of obs     =      3,536
                                                    F(1, 3534)        =       3.03
                                                    Prob > F          =     0.0819
                                                    R-squared         =     0.0008
                                                    Root MSE          =     .10476
    
    ------------------------------------------------------------------------------
                 |               Robust
    ldiffcost_~s | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            rmrf |   .2680922   .1540329     1.74   0.082    -.0339103    .5700946
           _cons |   .0002808   .0017616     0.16   0.873     -.003173    .0037346
    ------------------------------------------------------------------------------
    type mismatch
    r(109);
    I want to get the variables with negative t-statistics, and only include these in my average to put into 'UKIS1', then do the same for the next 6 months, and append these to form a single UKIS

    Is this the correct way to do it, and is there something I can do to fix my error?

  • #2
    What is line 3 supposed to do? I don't see any action guarded by the if statement. It seems like there should be an error message "{ required" at that point.

    What about the date variable? It looks like it is in American string format (month-day-year). Is date a string? If it is I suppose this will work, since only the month matters to this comparison. If it is a Stata date variable then a "type mismatch" would be reported.

    If you add
    Code:
    set trace on
    set tracedepth 1
    before the loop, you can at least find which command is causing the error message.

    Comment


    • #3
      This is yet another new thread that makes no cross-reference to existing threads you've started and continue to run. See https://www.statalist.org/forums/for...every-6-months

      See https://www.statalist.org/forums/for...ed-time-period for the advice given before on this point.

      The code here introduces yet more misconceptions because you are just guessing at code on a project that is, unfortunately, too difficult for you. I will point out some problems here, but this is absolutely my last contribution to your project. I can't agree to support you on your implicit terms.


      The separate command

      Code:
       if date >= "01-01-2004" & date <= "06-30-2004"
      will be legal if and only if date is a string variable, but the indications elsewhere are that it is numeric. But even if it were a string variable that command is interpreted as

      Code:
       if date[1] >= "01-01-2004" & date[1] <= "06-30-2004"
      with reference to the first observation. Nothing at all links that statement to the previous regress for all observations in your dataset.


      Perhaps what you intend is something more like


      Code:
      regress `var' rmrf if inrange(date, mdy(1,1,2004), mdy(6, 30, 2004))

      ]In principle comparisons of dates and strings usually fail, as already pointed out, So the string date "07-01-2004" fails the test above.

      Logic seems to imply that you lift the row mean calculation outside the loop.





      Last edited by Nick Cox; 29 Dec 2022, 07:44.

      Comment


      • #4
        Line 3 is an attempt to fix the regression in that time period- if it is a stata date, is there a proper format it needs to be for the if statement to work?

        Comment

        Working...
        X