Announcement

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

  • Using constraint with cnsreg to set the sum of all fixed effects to zero for large i

    Hi all,

    I am trying to perform event study with the package cnsreg (constrained linear regression), which is recommended by this event study guide https://www.aeaweb.org/articles?id=10.1257/jep.37.2.203. I think the idea is it allows us to be more clear about the constraints we are actually using because we need to define them explicitly.

    I think in packages like reghdfe the sum of all fixed effects is set to zero by default, but this is not the case with cnsreg. In the code provided by the author he writes out the constraints and then use them in the regression in the following way.

    constraint define 2 1.i + 2.i + 3.i + 4.i + 5.i +
    6.i + 7.i + 8.i + 9.i + 10.i = 0 ;

    cnsreg y D_m* D_p*
    ibn.t ibn.i , cluster(i) nocons constraints(2) collinear

    My question is a simple one, instead of having 10 people I have 1000+, so I would need to have constraint define 2 1.i + 2.i + 3.i + 4.i + 5.i + 6.i + 7.i + 8.i + 9.i + 10.i +....+ 1000.i = 0. I am not sure what the easiest way to do this would be.

    Apologies in advance if this is very obvious.


    Best,
    Angela












  • #2
    Constraining the dummy coefficients does not make much sense to me, but I have not read the paper to examine the context under which this is done. When using the within estimator, such constraints are necessary if you want to artificially report a constant. In the real sense, one cannot separate the constant from the fixed effects in these models. See https://www.stata.com/support/faqs/s...effects-model/ for a discussion. Now, the dummy variable regression is equivalent to the within estimator in a balanced panel only if you estimate the dummy coefficients save one, with no constraints imposed. Just in case there is some sense in what you want to attempt, creating such a list is not difficult:

    Code:
    local list
    forval d=1/999{
        local list `list' `d'.i+
    }
    local constraint "constraint define 1 `list' 1000.i=0"
    Res.:

    Code:
    . di "`constraint'"
    constraint define 1 1.i+ 2.i+ 3.i+ 4.i+ 5.i+ 6.i+ 7.i+ 8.i+ 9.i+ 10.i+ 11.i+ 12.i+ 13.i+ 14.i+ 15.i+ 16.i+ 17.i+ 18.i+ 19.i+ 20.i+ 2
    > 1.i+ 22.i+ 23.i+ 24.i+ 25.i+ 26.i+ 27.i+ 28.i+ 29.i+ 30.i+ 31.i+ 32.i+ 33.i+ 34.i+ 35.i+ 36.i+ 37.i+ 38.i+ 39.i+ 40.i+ 41.i+ 42.i+
    >  43.i+ 44.i+ 45.i+ 46.i+ 47.i+ 48.i+ 49.i+ 50.i+ 51.i+ 52.i+ 53.i+ 54.i+ 55.i+ 56.i+ 57.i+ 58.i+ 59.i+ 60.i+ 61.i+ 62.i+ 63.i+ 64.
    > i+ 65.i+ 66.i+ 67.i+ 68.i+ 69.i+ 70.i+ 71.i+ 72.i+ 73.i+ 74.i+ 75.i+ 76.i+ 77.i+ 78.i+ 79.i+ 80.i+ 81.i+ 82.i+ 83.i+ 84.i+ 85.i+ 8
    > 6.i+ 87.i+ 88.i+ 89.i+ 90.i+ 91.i+ 92.i+ 93.i+ 94.i+ 95.i+ 96.i+ 97.i+ 98.i+ 99.i+ 100.i+ 101.i+ 102.i+ 103.i+ 104.i+ 105.i+ 106.i
    > + 107.i+ 108.i+ 109.i+ 110.i+ 111.i+ 112.i+ 113.i+ 114.i+ 115.i+ 116.i+ 117.i+ 118.i+ 119.i+ 120.i+ 121.i+ 122.i+ 123.i+ 124.i+ 12
    > 5.i+ 126.i+ 127.i+ 128.i+ 129.i+ 130.i+ 131.i+ 132.i+ 133.i+ 134.i+ 135.i+ 136.i+ 137.i+ 138.i+ 139.i+ 140.i+ 141.i+ 142.i+ 143.i+
    >  144.i+ 145.i+ 146.i+ 147.i+ 148.i+ 149.i+ 150.i+ 151.i+ 152.i+ 153.i+ 154.i+ 155.i+ 156.i+ 157.i+ 158.i+ 159.i+ 160.i+ 161.i+ 162
    > .i+ 163.i+ 164.i+ 165.i+ 166.i+ 167.i+ 168.i+ 169.i+ 170.i+ 171.i+ 172.i+ 173.i+ 174.i+ 175.i+ 176.i+ 177.i+ 178.i+ 179.i+ 180.i+ 
    > 181.i+ 182.i+ 183.i+ 184.i+ 185.i+ 186.i+ 187.i+ 188.i+ 189.i+ 190.i+ 191.i+ 192.i+ 193.i+ 194.i+ 195.i+ 196.i+ 197.i+ 198.i+ 199.
    > i+ 200.i+ 201.i+ 202.i+ 203.i+ 204.i+ 205.i+ 206.i+ 207.i+ 208.i+ 209.i+ 210.i+ 211.i+ 212.i+ 213.i+ 214.i+ 215.i+ 216.i+ 217.i+ 2
    > 18.i+ 219.i+ 220.i+ 221.i+ 222.i+ 223.i+ 224.i+ 225.i+ 226.i+ 227.i+ 228.i+ 229.i+ 230.i+ 231.i+ 232.i+ 233.i+ 234.i+ 235.i+ 236.i
    > + 237.i+ 238.i+ 239.i+ 240.i+ 241.i+ 242.i+ 243.i+ 244.i+ 245.i+ 246.i+ 247.i+ 248.i+ 249.i+ 250.i+ 251.i+ 252.i+ 253.i+ 254.i+ 25
    > 5.i+ 256.i+ 257.i+ 258.i+ 259.i+ 260.i+ 261.i+ 262.i+ 263.i+ 264.i+ 265.i+ 266.i+ 267.i+ 268.i+ 269.i+ 270.i+ 271.i+ 272.i+ 273.i+
    >  274.i+ 275.i+ 276.i+ 277.i+ 278.i+ 279.i+ 280.i+ 281.i+ 282.i+ 283.i+ 284.i+ 285.i+ 286.i+ 287.i+ 288.i+ 289.i+ 290.i+ 291.i+ 292
    > .i+ 293.i+ 294.i+ 295.i+ 296.i+ 297.i+ 298.i+ 299.i+ 300.i+ 301.i+ 302.i+ 303.i+ 304.i+ 305.i+ 306.i+ 307.i+ 308.i+ 309.i+ 310.i+ 
    > 311.i+ 312.i+ 313.i+ 314.i+ 315.i+ 316.i+ 317.i+ 318.i+ 319.i+ 320.i+ 321.i+ 322.i+ 323.i+ 324.i+ 325.i+ 326.i+ 327.i+ 328.i+ 329.
    > i+ 330.i+ 331.i+ 332.i+ 333.i+ 334.i+ 335.i+ 336.i+ 337.i+ 338.i+ 339.i+ 340.i+ 341.i+ 342.i+ 343.i+ 344.i+ 345.i+ 346.i+ 347.i+ 3
    > 48.i+ 349.i+ 350.i+ 351.i+ 352.i+ 353.i+ 354.i+ 355.i+ 356.i+ 357.i+ 358.i+ 359.i+ 360.i+ 361.i+ 362.i+ 363.i+ 364.i+ 365.i+ 366.i
    > + 367.i+ 368.i+ 369.i+ 370.i+ 371.i+ 372.i+ 373.i+ 374.i+ 375.i+ 376.i+ 377.i+ 378.i+ 379.i+ 380.i+ 381.i+ 382.i+ 383.i+ 384.i+ 38
    > 5.i+ 386.i+ 387.i+ 388.i+ 389.i+ 390.i+ 391.i+ 392.i+ 393.i+ 394.i+ 395.i+ 396.i+ 397.i+ 398.i+ 399.i+ 400.i+ 401.i+ 402.i+ 403.i+
    >  404.i+ 405.i+ 406.i+ 407.i+ 408.i+ 409.i+ 410.i+ 411.i+ 412.i+ 413.i+ 414.i+ 415.i+ 416.i+ 417.i+ 418.i+ 419.i+ 420.i+ 421.i+ 422
    > .i+ 423.i+ 424.i+ 425.i+ 426.i+ 427.i+ 428.i+ 429.i+ 430.i+ 431.i+ 432.i+ 433.i+ 434.i+ 435.i+ 436.i+ 437.i+ 438.i+ 439.i+ 440.i+ 
    > 441.i+ 442.i+ 443.i+ 444.i+ 445.i+ 446.i+ 447.i+ 448.i+ 449.i+ 450.i+ 451.i+ 452.i+ 453.i+ 454.i+ 455.i+ 456.i+ 457.i+ 458.i+ 459.
    > i+ 460.i+ 461.i+ 462.i+ 463.i+ 464.i+ 465.i+ 466.i+ 467.i+ 468.i+ 469.i+ 470.i+ 471.i+ 472.i+ 473.i+ 474.i+ 475.i+ 476.i+ 477.i+ 4
    > 78.i+ 479.i+ 480.i+ 481.i+ 482.i+ 483.i+ 484.i+ 485.i+ 486.i+ 487.i+ 488.i+ 489.i+ 490.i+ 491.i+ 492.i+ 493.i+ 494.i+ 495.i+ 496.i
    > + 497.i+ 498.i+ 499.i+ 500.i+ 501.i+ 502.i+ 503.i+ 504.i+ 505.i+ 506.i+ 507.i+ 508.i+ 509.i+ 510.i+ 511.i+ 512.i+ 513.i+ 514.i+ 51
    > 5.i+ 516.i+ 517.i+ 518.i+ 519.i+ 520.i+ 521.i+ 522.i+ 523.i+ 524.i+ 525.i+ 526.i+ 527.i+ 528.i+ 529.i+ 530.i+ 531.i+ 532.i+ 533.i+
    >  534.i+ 535.i+ 536.i+ 537.i+ 538.i+ 539.i+ 540.i+ 541.i+ 542.i+ 543.i+ 544.i+ 545.i+ 546.i+ 547.i+ 548.i+ 549.i+ 550.i+ 551.i+ 552
    > .i+ 553.i+ 554.i+ 555.i+ 556.i+ 557.i+ 558.i+ 559.i+ 560.i+ 561.i+ 562.i+ 563.i+ 564.i+ 565.i+ 566.i+ 567.i+ 568.i+ 569.i+ 570.i+ 
    > 571.i+ 572.i+ 573.i+ 574.i+ 575.i+ 576.i+ 577.i+ 578.i+ 579.i+ 580.i+ 581.i+ 582.i+ 583.i+ 584.i+ 585.i+ 586.i+ 587.i+ 588.i+ 589.
    > i+ 590.i+ 591.i+ 592.i+ 593.i+ 594.i+ 595.i+ 596.i+ 597.i+ 598.i+ 599.i+ 600.i+ 601.i+ 602.i+ 603.i+ 604.i+ 605.i+ 606.i+ 607.i+ 6
    > 08.i+ 609.i+ 610.i+ 611.i+ 612.i+ 613.i+ 614.i+ 615.i+ 616.i+ 617.i+ 618.i+ 619.i+ 620.i+ 621.i+ 622.i+ 623.i+ 624.i+ 625.i+ 626.i
    > + 627.i+ 628.i+ 629.i+ 630.i+ 631.i+ 632.i+ 633.i+ 634.i+ 635.i+ 636.i+ 637.i+ 638.i+ 639.i+ 640.i+ 641.i+ 642.i+ 643.i+ 644.i+ 64
    > 5.i+ 646.i+ 647.i+ 648.i+ 649.i+ 650.i+ 651.i+ 652.i+ 653.i+ 654.i+ 655.i+ 656.i+ 657.i+ 658.i+ 659.i+ 660.i+ 661.i+ 662.i+ 663.i+
    >  664.i+ 665.i+ 666.i+ 667.i+ 668.i+ 669.i+ 670.i+ 671.i+ 672.i+ 673.i+ 674.i+ 675.i+ 676.i+ 677.i+ 678.i+ 679.i+ 680.i+ 681.i+ 682
    > .i+ 683.i+ 684.i+ 685.i+ 686.i+ 687.i+ 688.i+ 689.i+ 690.i+ 691.i+ 692.i+ 693.i+ 694.i+ 695.i+ 696.i+ 697.i+ 698.i+ 699.i+ 700.i+ 
    > 701.i+ 702.i+ 703.i+ 704.i+ 705.i+ 706.i+ 707.i+ 708.i+ 709.i+ 710.i+ 711.i+ 712.i+ 713.i+ 714.i+ 715.i+ 716.i+ 717.i+ 718.i+ 719.
    > i+ 720.i+ 721.i+ 722.i+ 723.i+ 724.i+ 725.i+ 726.i+ 727.i+ 728.i+ 729.i+ 730.i+ 731.i+ 732.i+ 733.i+ 734.i+ 735.i+ 736.i+ 737.i+ 7
    > 38.i+ 739.i+ 740.i+ 741.i+ 742.i+ 743.i+ 744.i+ 745.i+ 746.i+ 747.i+ 748.i+ 749.i+ 750.i+ 751.i+ 752.i+ 753.i+ 754.i+ 755.i+ 756.i
    > + 757.i+ 758.i+ 759.i+ 760.i+ 761.i+ 762.i+ 763.i+ 764.i+ 765.i+ 766.i+ 767.i+ 768.i+ 769.i+ 770.i+ 771.i+ 772.i+ 773.i+ 774.i+ 77
    > 5.i+ 776.i+ 777.i+ 778.i+ 779.i+ 780.i+ 781.i+ 782.i+ 783.i+ 784.i+ 785.i+ 786.i+ 787.i+ 788.i+ 789.i+ 790.i+ 791.i+ 792.i+ 793.i+
    >  794.i+ 795.i+ 796.i+ 797.i+ 798.i+ 799.i+ 800.i+ 801.i+ 802.i+ 803.i+ 804.i+ 805.i+ 806.i+ 807.i+ 808.i+ 809.i+ 810.i+ 811.i+ 812
    > .i+ 813.i+ 814.i+ 815.i+ 816.i+ 817.i+ 818.i+ 819.i+ 820.i+ 821.i+ 822.i+ 823.i+ 824.i+ 825.i+ 826.i+ 827.i+ 828.i+ 829.i+ 830.i+ 
    > 831.i+ 832.i+ 833.i+ 834.i+ 835.i+ 836.i+ 837.i+ 838.i+ 839.i+ 840.i+ 841.i+ 842.i+ 843.i+ 844.i+ 845.i+ 846.i+ 847.i+ 848.i+ 849.
    > i+ 850.i+ 851.i+ 852.i+ 853.i+ 854.i+ 855.i+ 856.i+ 857.i+ 858.i+ 859.i+ 860.i+ 861.i+ 862.i+ 863.i+ 864.i+ 865.i+ 866.i+ 867.i+ 8
    > 68.i+ 869.i+ 870.i+ 871.i+ 872.i+ 873.i+ 874.i+ 875.i+ 876.i+ 877.i+ 878.i+ 879.i+ 880.i+ 881.i+ 882.i+ 883.i+ 884.i+ 885.i+ 886.i
    > + 887.i+ 888.i+ 889.i+ 890.i+ 891.i+ 892.i+ 893.i+ 894.i+ 895.i+ 896.i+ 897.i+ 898.i+ 899.i+ 900.i+ 901.i+ 902.i+ 903.i+ 904.i+ 90
    > 5.i+ 906.i+ 907.i+ 908.i+ 909.i+ 910.i+ 911.i+ 912.i+ 913.i+ 914.i+ 915.i+ 916.i+ 917.i+ 918.i+ 919.i+ 920.i+ 921.i+ 922.i+ 923.i+
    >  924.i+ 925.i+ 926.i+ 927.i+ 928.i+ 929.i+ 930.i+ 931.i+ 932.i+ 933.i+ 934.i+ 935.i+ 936.i+ 937.i+ 938.i+ 939.i+ 940.i+ 941.i+ 942
    > .i+ 943.i+ 944.i+ 945.i+ 946.i+ 947.i+ 948.i+ 949.i+ 950.i+ 951.i+ 952.i+ 953.i+ 954.i+ 955.i+ 956.i+ 957.i+ 958.i+ 959.i+ 960.i+ 
    > 961.i+ 962.i+ 963.i+ 964.i+ 965.i+ 966.i+ 967.i+ 968.i+ 969.i+ 970.i+ 971.i+ 972.i+ 973.i+ 974.i+ 975.i+ 976.i+ 977.i+ 978.i+ 979.
    > i+ 980.i+ 981.i+ 982.i+ 983.i+ 984.i+ 985.i+ 986.i+ 987.i+ 988.i+ 989.i+ 990.i+ 991.i+ 992.i+ 993.i+ 994.i+ 995.i+ 996.i+ 997.i+ 9
    > 98.i+ 999.i+ 1000.i=0
    Last edited by Andrew Musau; 20 Jun 2023, 10:48.

    Comment


    • #3
      Hi Andrew,

      Thanks for this. I think restricting the dummies in this case is just because the fixed effects can not all be separately identified, similar to setting one of the fixed effects to be zero.

      Best,
      Angela

      Comment


      • #4
        Constraining the dummies will have an effect on your estimates. What am I missing?

        Code:
        webuse grunfeld, clear
        keep if company<5
        regress invest mvalue kstock ibn.company, nocons 
        constraint define 1 1.company+2.company+3.company+4.company=0
        cnsreg invest mvalue kstock ibn.company, nocons cons(1)
        Res.:

        Code:
        . regress invest mvalue kstock ibn.company, nocons 
        
              Source |       SS           df       MS      Number of obs   =        80
        -------------+----------------------------------   F(6, 74)        =    387.50
               Model |  12909484.9         6  2151580.81   Prob > F        =    0.0000
            Residual |   410886.53        74  5552.52067   R-squared       =    0.9692
        -------------+----------------------------------   Adj R-squared   =    0.9667
               Total |  13320371.4        80  166504.643   Root MSE        =    74.515
        
        ------------------------------------------------------------------------------
              invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
              mvalue |   .1124064   .0174713     6.43   0.000      .077594    .1472188
              kstock |   .3449139   .0260587    13.24   0.000     .2929909    .3968369
                     |
             company |
                  1  |   -102.786   73.21054    -1.40   0.165    -248.6612    43.08918
                  2  |   87.12973   36.46538     2.39   0.019     14.47087    159.7886
                  3  |   -253.948   35.74711    -7.10   0.000    -325.1757   -182.7204
                  4  |   -33.6168    20.1564    -1.67   0.100     -73.7793    6.545704
        ------------------------------------------------------------------------------
        
        . 
        . constraint define 1 1.company+2.company+3.company+4.company=0
        
        . 
        . cnsreg invest mvalue kstock ibn.company, nocons cons(1)
        
        Constrained linear regression                          Number of obs =      80
                                                               F(5, 75)      =  445.94
                                                               Prob > F      =  0.0000
                                                               Root MSE      = 76.0241
        
         ( 1)  1bn.company + 2.company + 3.company + 4.company = 0
        ------------------------------------------------------------------------------
              invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
              mvalue |   .0790679   .0057749    13.69   0.000     .0675637     .090572
              kstock |   .3515576   .0263731    13.33   0.000     .2990198    .4040955
                     |
             company |
                  1  |   41.11466   16.75361     2.45   0.016     7.739755    74.48957
                  2  |   154.6333   14.77163    10.47   0.000     125.2067    184.0599
                  3  |  -188.1609    14.9248   -12.61   0.000    -217.8927   -158.4292
                  4  |  -7.586977   15.79674    -0.48   0.632     -39.0557    23.88175
        ------------------------------------------------------------------------------

        Comment

        Working...
        X