Announcement

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

  • Placebo test

    Hello every one

    I am addressing a problem with the process of Placebo test

    First, I am using the following process
    HTML Code:
    set seed 12345
    
    gen randomplacebo = runiform()
    bysort code (randomplacebo): keep if _n == 1 
    gen placebo_gb = 0 
    bysort code: gen rank = _n 
    bysort code: replace placebo_gb = 1 if rank <= 167 
    
    
    gen random_year = floor(2016 + 7 * runiform())
    replace random_year = . 
    replace random_year = floor(2016 + 7 * runiform()) if placebo_gb == 1
    
    gen PlacPost = (year >= random_year & placebo_gb == 1) 
    
    matrix plac_coeff = J(1000, 1, .)
    
    forval i = 1/1000 {
        quietly reg  SL PlacPost growth Bsize dual bmeet bindp size leverage mtb roa own soe , robust
        matrix plac_coeff[`i', 1] = _b[PlacPost] 
    }
    the problem represent in two issues
    1- the matrix command does not create the plac_coeff
    I don't know why
    thenI tried to fix it all of a sudden the second issue appeared which is getting an error message (reg is unrecognized command)

    Below id the data example
    HTML Code:
    ---------------------- copy starting from the next line -----------------------
    [CODE]
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double SL byte gb double growth float Bsize byte(dual bmeet bindp) double(size leverage mtb roa Institutionalownership) byte tateowned1no0
                       . 0     .049910983979371 11 0 16 4 29.351484298706055  .9154999852180481  30.661100387573242   .008500000461935997             .67149 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .09834200143814087 0      .25523611968287  9 0  5 3 19.305076599121094  .4032000005245209   .2475000023841858   .026599999517202377            .356486 0
     .053509000688791275 0  -.19098814131373998 14 0  9 5 21.620494842529297  .4593999981880188   .9158999919891357   -.14079999923706055 .19131399999999998 0
     .021412000060081482 0   .16732135609520998  9 0 14 3 23.187393188476563  .6413999795913696  1.2348999977111816   .047200001776218414            .370434 1
      .07607199996709824 0     .035608975975038  6 0  9 3  20.33896255493164 .47429999709129334  .20190000534057617   -.04989999905228615            .280746 0
      .11843899637460709 0     .020846702148776  7 0  7 3 20.255861282348633  .1005999967455864  .22930000722408295    .03669999912381172            .304193 1
     .022972000762820244 0      .10108411233325  9 1 12 3 24.119443893432617  .6499000191688538  3.2221999168395996   .023399999365210533 .20340499999999997 0
      .06369999796152115 0  .054143947990315994 10 0 18 4   21.9090576171875  .8195000290870667  1.2246999740600586   -.22779999673366547            .356523 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .015778999775648117 0      .36626875061248  7 0 15 3 23.882762908935547  .6520000100135803  1.9980000257492065     .2493000030517578 .34084200000000003 1
     .030642999336123466 0     -.10915888625072  8 1  6 3  17.64130210876465  .7081000208854675 .008200000040233135  -.002199999988079071            .211736 0
     .011579000391066074 0      .46100472358042  9 0 12 3 23.180103302001953  .8062999844551086   1.222499966621399    .03909999877214432             .24984 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .07369200140237808 0    -.040811754553639  7 1 10 3 20.402915954589844  .6327999830245972   .3495999872684479   .012400000356137753                  0 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .030626999214291573 .                    .  . .  . .                  .                  .                   .                     .                  . .
      .03307599946856499 0     .062322601922208  9 0 16 3  21.17170524597168  .7148000001907349  .36959999799728394   .017500000074505806            .448203 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .01860399916768074 0   .18169905564574002  8 0 16 3 21.229055404663086 .33709999918937683  .22579999268054962   .056299999356269836  .7832389999999999 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .014062000438570976 0                    .  9 0 11 3  24.13275718688965  .4814999997615814  1.0128999948501587    .07769999653100967                  . 1
      .01681699976325035 0 -.003924904188825701 10 0  9 4  24.47549057006836  .5436999797821045  3.2351999282836914    .04149999842047691            .735984 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .03072500042617321 0        .119258384875  9 0 14 3  23.39475440979004  .4277999997138977  1.1057000160217285    .06639999896287918            .801096 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .17437300086021423 0   .08323242724564199  7 0  5 3 20.204423904418945 3.0195000171661377    .593999981880188    .08169999718666077              .1133 0
     .011056000366806984 0      .50462039954484 11 0  8 4 22.998014450073242  .5861999988555908  1.0130000114440918     .1671999990940094            .355596 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
       .0335410013794899 0    -.038441168975833  6 1 18 3  21.79387855529785  .0560000017285347   .4708999991416931   .041600000113248825            .354792 0
     .013434999622404575 0      .21652860506308  8 0 26 3 25.791440963745117   .670199990272522   6.424699783325195    .02810000069439411            .490576 0
      .11671900004148483 0  -.17310673797027998 11 0 13 4 21.358858108520508  .4779999852180481  1.1654000282287598     .0674000009894371 .36304499999999995 0
      .06391999870538712 0     -.11464818125397  8 1  4 3  24.32569122314453  .7760999798774719   6.949900150299072 .00019999999494757503  .7138549999999999 0
     .022823000326752663 .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .02340400032699108 0   .11880087320103999 18 0 17 6  25.95850944519043   .853600025177002   4.844099998474121   .017400000244379044            .808165 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .05964000150561333 0    -.021250012970181 11 0 13 4  21.38636589050293  .5866000056266785   .1363999992609024    .10689999908208847            .433977 0
     .024584999307990074 0      .29886796731402  9 0  5 3 20.561124801635742  .6726999878883362   .2362000048160553    .11649999767541885            .496198 0
      .01816900074481964 0      .51211310174228  9 0 12 3   22.7997989654541   .588100016117096  1.2303999662399292    .03620000183582306            .566122 1
     .028418999165296555 0     .039461170949946  7 1  6 3  23.26841926574707  .5432999730110168   3.208699941635132    .02290000021457672            .211519 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .03984300047159195 0    -.034060130126626  9 0 12 3 22.451797485351563  .5430999994277954   .7978000044822693    .01720000058412552            .464224 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .011703000403940678 0      .12940504787279 13 0  7 5 23.348308563232422   .554099977016449   .6209999918937683   .010400000028312206            .693481 1
       .0807889997959137 0      .52796498371664  9 1 30 3 22.544965744018555  .4049000144004822  .23420000076293945     .0731000006198883  .7762720000000001 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
       .0571569986641407 0     -.16477859241217  6 0  5 3 21.392717361450195  .7064999938011169   .6272000074386597    .02319999970495701  .6247590000000001 1
    .0024399999529123306 0      .18817371391192  9 0 39 3 24.210969924926758  .6710000038146973   .7857000231742859   .022700000554323196 .46820799999999996 1
       .0398470014333725 0                    .  9 0 11 3  20.36865997314453  .7486000061035156  .09749999642372131    -.9986000061035156                  . 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .014310999773442745 0      .42255819614562  8 0 20 3 23.034378051757813  .7049999833106995  1.3410999774932861   .006800000090152025 .45431600000000005 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .015792999416589737 0  .043902551988715004  9 0  8 3  23.24738311767578 .14100000262260437    .760699987411499     .0471000000834465            .700849 1
      .03773999959230423 0                    .  7 0 12 3 22.496482849121094   .552299976348877   1.079300045967102   .010200000368058681                  . 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .015852000564336777 0      .14867623157033 15 0 11 5 22.217166900634766   .388700008392334    .534500002861023    .04960000142455101             .42896 1
    .0032279998995363712 0   .08942154003554201 12 1 13 4 25.800275802612305  .6621999740600586   3.041100025177002   .023099999874830246 .29118099999999997 0
      .06755799800157547 0     .083699528470525  7 0 20 3  22.83640480041504  .6952000260353088   .8960000276565552   .025299999862909317            .465391 0
      .08585699647665024 0      .49467501404662  9 0 11 3 21.635513305664063  .6067000031471252   1.152400016784668    .04450000077486038            .454894 1
      .06205400079488754 0     .042826530949328  9 0 10 3 21.558467864990234   .486299991607666   .7074000239372253   .013899999670684338             .29948 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .12762600183486938 0      .12522447336726 13 1 15 4 21.942197799682617  .7487000226974487   .2957000136375427    .09470000118017197            .023908 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .024248000234365463 0   -.0049410912839277  9 0  0 3 21.811241149902344  .2644999921321869   .6065999865531921   .044599998742341995             .32241 0
    .0025740000419318676 0      .22374620226563 11 0 11 4  27.12187957763672  .8219000101089478   5.038899898529053   .017500000074505806             .76265 1
     .004184000194072723 0      .58460762144208  7 1 21 3 25.606090545654297  .7771999835968018  1.4117000102996826    .05220000073313713  .6143339999999999 0
     .004726000130176544 0      .10496765836308 14 1  9 5 25.297420501708984  .5968999862670898  1.1497999429702759    .08990000188350677            .500071 0
    .0030980000738054514 0      .15960978622249 14 1  8 5 25.968381881713867  .7027999758720398  2.9449000358581543   .051899999380111694             .30975 1
     .022926999256014824 0    -.047803615854213  9 0 11 3   23.4027042388916  .4269999861717224  1.6261999607086182   .018300000578165054            .550543 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .005884999874979258 0      .27893578476124  9 0 17 3  24.71535873413086  .6816999912261963   2.707200050354004    .03799999877810478 .41822899999999996 1
      .02875399962067604 0      .11162548692244  9 1  7 3 20.894826889038086  .7038000226020813  .27709999680519104     .0568000003695488            .034698 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
       .3730219900608063 0     -.20860610039283  8 0 13 3 19.938995361328125  .6985999941825867   .1712000072002411   -.10729999840259552 .21473199999999998 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .027778999879956245 0                    .  9 0 11 3  22.91562271118164  .8416000008583069  1.4505000114440918   .005799999926239252                  . 1
      .12467099726200104 0   .16724316933720002  9 0  5 3 22.291383743286133  .7404000163078308   2.175600051879883    .03790000081062317            .637891 1
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
     .026197999715805054 0 -.007918100740661101  9 0  9 3 26.237625122070313  .8392999768257141  13.792900085449219 -.0044999998062849045            .521751 0
                       . .                    .  . .  . .                  .                  .                   .                     .                  . .
      .04418500140309334 0     .028251837408894  9 0  5 4  23.13256072998047  .5645999908447266  2.9598000049591064    .01720000058412552  .5731430000000001 1
      .06007400155067444 0  -.08107873104593401  9 0  7 3 22.851938247680664  .4941999912261963  1.5194000005722046    .04320000112056732            .459741 0
     .024880999699234962 0     .016766102680143  9 1 12 3 22.069517135620117  .4869999885559082   .7854999899864197   .029100000858306885 .49847299999999994 1
       .1817139983177185 0       .1229802919175 11 0 14 4 21.961795806884766  .8253999948501587   2.895900011062622  .0026000000070780516            .086064 1
    end
    [/CODE]
    ---------

  • #2
    it's probably not estimating the coefficient due to a coding error.

    ritest will do this for you.

    what exactly are you trying to do? what is the nature of the data? is this DID?

    Comment


    • #3
      Like George Ford, I do not understand exactly what is being attempted with this code. I'll just comment on a few items that catch my attention.
      [quote]getting an error message (reg is unrecognized command)[quote]

      The most common cause of this kind of message when the command, -reg- in this case, is clearly a valid Stata command, is that the code in question has been copy/pasted from a source that may include non-printing formatting characters. Examples of such sources include Microsoft Word documents, PDF files, and websites (including, yes, Statalist). These non-printing characters do not show up in the Results window or do-file, but they are there and Stata's parser "sees" them. So it is likely that somewhere in what looks to our eyes like -reg-, there is embedded one or more of these invisible characters. While there are some ways to have Stata identify them and remove them from the code, they are somewhat complicated. It is usually simpler to resolve this kind of problem by simply deleting that line of code from the program and retyping it by hand. (Do not repeat the copy/paste operation--it will give you the same problem every time.) Be careful to avoid introducing typos.

      Code:
      gen random_year = floor(2016 + 7 * runiform())
      replace random_year = .
      replace random_year = floor(2016 + 7 * runiform()) if placebo_gb == 1
      This sequence of code, though legal, and probably not the cause of the problems reported by O.P., is awkward, unnecessarily complicated, and can be easily improved:
      Code:
      gen random_year = runiformint(2016, 2022) if placebo_gb == 1
      Finally I'll point out that the example data shown is of no use for troubleshooting the questions posed because it does not include the variables code, and year, which appear in many of the commands. (It may be missing other variables as well--I stopped checking after finding out about those two.)

      Comment


      • #4
        Originally posted by George Ford View Post
        it's probably not estimating the coefficient due to a coding error.

        ritest will do this for you.

        what exactly are you trying to do? what is the nature of the data? is this DID?
        First of all thank you very much for responding
        Secondly, this is not a DID I am trying to perform placebo test I just typed POST randomly
        my dependent variable id stock return and the IV is green innovation. I am trying here to apply placebo as test for addressing endogeneity concern (some call it for robustness)

        Comment


        • #5
          [QUOTE=Clyde Schechter;n1769932]Like George Ford, I do not understand exactly what is being attempted with this code. I'll just comment on a few items that catch my attention.
          [quote]getting an error message (reg is unrecognized command)

          The most common cause of this kind of message when the command, -reg- in this case, is clearly a valid Stata command, is that the code in question has been copy/pasted from a source that may include non-printing formatting characters. Examples of such sources include Microsoft Word documents, PDF files, and websites (including, yes, Statalist). These non-printing characters do not show up in the Results window or do-file, but they are there and Stata's parser "sees" them. So it is likely that somewhere in what looks to our eyes like -reg-, there is embedded one or more of these invisible characters. While there are some ways to have Stata identify them and remove them from the code, they are somewhat complicated. It is usually simpler to resolve this kind of problem by simply deleting that line of code from the program and retyping it by hand. (Do not repeat the copy/paste operation--it will give you the same problem every time.) Be careful to avoid introducing typos.

          Code:
          gen random_year = floor(2016 + 7 * runiform())
          replace random_year = .
          replace random_year = floor(2016 + 7 * runiform()) if placebo_gb == 1
          This sequence of code, though legal, and probably not the cause of the problems reported by O.P., is awkward, unnecessarily complicated, and can be easily improved:
          Code:
          gen random_year = runiformint(2016, 2022) if placebo_gb == 1
          Finally I'll point out that the example data shown is of no use for troubleshooting the questions posed because it does not include the variables code, and year, which appear in many of the commands. (It may be missing other variables as well--I stopped checking after finding out about those two.)
          Exactly I copied it from a word file.
          But, even when I retyped the command manually still gives same error message ( only with this command)

          I am here reposting the data again with code and year
          HTML Code:
          ---------------------- copy starting from the next line -----------------------
          [CODE]
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input long code int year double SL byte gd double growth float Bsize byte(dual bmeet bindp) double(size leverage mtb roa Institutionalownership) byte tateowned1no0 long sic1
          600598 2016  .008914000354707241 0     .070149881532048  9 0 10 4  22.76995849609375  .26159998774528503  .3569999933242798   .09529999643564224            .693406 1 1
            2041 2016  .023329000920057297 0        .039535125972 12 0  9 4 22.220090866088867  .18050000071525574  .2689000070095062   .11919999867677689            .693445 0 1
          300511 2016    2.101619005203247 0      .38642983513327  9 1  9 3   21.6236629486084   .4758000075817108  .3391999900341034    .0502999983727932             .01489 0 1
          601118 2016  .009176000021398067 0     .045937407312199  8 1 13 3 23.340232849121094   .4018999934196472  .5005000233650208  .004800000227987766            .751737 1 1
             998 2016  .007809999864548445 0      .58105084565988 15 0  9 5 22.795534133911133   .2728999853134155 .29510000348091125   .07739999890327454            .517045 1 1
          600108 2016  .008716999553143978 0  .023180536720126002  9 0  9 4 22.776878356933594    .392300009727478  .7001000046730042  .010200000368058681 .33267800000000003 1 1
            2772 2016  .021524999290704727 0      .91034601805157  9 0 14 3 21.890966415405273  .28690001368522644  .4185999929904938   .06589999794960022            .189754 0 1
          300189 2016   .01571900025010109 0      .41904139788627  8 0 14 3 21.898082733154297  .35359999537467957  .6021999716758728  .010300000198185444            .109902 0 1
          300087 2016  .030520999804139137 0      .29126510249498  9 1 10 4 21.081260681152344  .38830000162124634 .33809998631477356   .04129999876022339            .299058 1 1
          600371 2016   .03388400003314018 0   .12000018462305001  9 0  4 3   20.4335994720459  .40310001373291016  .2037000060081482   .07980000227689743            .527791 0 1
          600359 2016  .019850000739097595 0     .020898937387623  7 0 12 3 21.753833770751953   .7639999985694885  .7822999954223633  -.06430000066757202             .45572 1 1
          600506 2016   .04126900061964989 0 -.037895376708855004  7 0  6 3 19.461305618286133 .054999999701976776 .05490000173449516  -.02019999921321869            .241222 1 1
          600313 2016  .022995999082922935 0      .10638569535479  7 1 10 3 22.139551162719727   .3781999945640564  .5770999789237976   .02370000071823597            .460854 1 1
          600354 2016  .025172999128699303 0     -.14062336299388 11 0  5 4  21.83226776123047   .5393999814987183  .6304000020027161   -.0982000008225441            .257316 1 1
          600540 2016  .031089000403881073 0  -.13390820699230999  8 0  8 3 21.650381088256836   .7888000011444092  .6783999800682068   -.2632000148296356 .43418599999999996 1 1
             592 2016  .008729999884963036 0   .09812774160333801  5 0 11 2  22.15131950378418    .163100004196167 .31940001249313354 .0013000000035390258             .36186 0 2
          600265 2016    .3242799937725067 0     -.03959161763618  9 1 15 3 19.612668991088867   .9473000168800354 .08259999752044678   .10320000350475311            .524501 0 2
            2679 2016  .032235998660326004 0    .0099837696076591  9 0  4 3 21.235795974731445   .5582000017166138 .30219998955726624  .015300000086426735            .724847 1 2
            2200 2016   .02704799920320511 0   .19142199341091998  9 0 12 3  21.95781135559082    .710099995136261   .796999990940094  .021400000900030136 .37574599999999997 1 2
             735 2016  .013895000331103802 0       .3735739845119  7 0 11 3 22.545337677001953  .42719998955726624  .7501000165939331  .016699999570846558            .376747 0 3
            2458 2016   .01929599978029728 0       .1038669145384  9 0  6 3 21.384437561035156  .23880000412464142  .1687999963760376   .30329999327659607            .292431 0 3
            2234 2016   .01958799920976162 0   .20432180067566003  9 0  6 3  21.50198745727539   .5270000100135803   .334199994802475    .0771000012755394            .312563 0 3
          300106 2016  .029733000323176384 0      .22106668914585  9 0 10 3  21.74315643310547   .6054999828338623  .8134999871253967  -.01850000023841858             .60244 1 3
            2157 2016  .009487000294029713 0      .25558743202964  5 0 19 2 23.229522705078125   .4927000105381012  .9136999845504761   .09430000185966492 .38600900000000005 0 3
            2124 2016  .021980000659823418 0      .26573949882416  7 0 12 3  21.63558578491211  .42800000309944153  .3224000036716461    .1671999990940094            .019723 0 3
          300313 2016   .02997099980711937 0    -.062005956417846  9 0 14 3  20.56704330444336   .5310999751091003  .2281000018119812  -.20759999752044678            .596462 0 3
            2321 2016    .0164560005068779 0      .24993761274266  9 1 11 3  22.54847526550293   .5598000288009644 1.0842000246047974   .01850000023841858 .43652700000000005 0 3
          600975 2016  .015824999660253525 0      .13246387707995  8 0  8 3  21.37289810180664   .3224000036716461  .3368000090122223   .09629999846220016            .346346 1 3
            2299 2016  .011675000190734863 0      .17343661090761  9 1  6 3 23.157943725585938   .4512999951839447 .48410001397132874  .061000000685453415            .718917 0 3
          300498 2016  .005229000002145767 0      .26586817495718 12 0 16 4 24.447467803955078     .24269999563694  .2705000042915344   .33000001311302185            .013768 0 3
            2714 2016  .006407999899238348 0      .82967985203746  8 1 16 3  23.28291893005371   .5622000098228455  .5372999906539917    .2321999967098236            .212272 0 3
            2477 2016  .006264000199735165 0    .6732491944299901 11 1  8 4 23.552236557006836   .5982999801635742  1.075600028038025    .0640999972820282 .11859700000000001 0 3
          600467 2016  .013515000231564045 0     .035659517651131  8 0  7 3 22.394405364990234   .4404999911785126  .8070999979972839  .008500000461935997 .47781199999999996 0 4
            2086 2016  .016832999885082245 0      .01999870229108  9 1 10 3 22.069543838500977  .24879999458789825  .4875999987125397   .01940000057220459            .400681 0 4
            2696 2016   .09171099960803986 0     .014848796003379  5 1 15 3  21.37256622314453   .4140999913215637  .4749000072479248   .03539999946951866            .067599 1 4
            2069 2016   .02625199966132641 0    -.032804763084038 10 1 13 4 22.157297134399414   .8062000274658203   .531499981880188 -.012799999676644802            .662012 1 4
             798 2016  .029833000153303146 0      .35961263377891  6 0  7 2 20.617441177368164  .34869998693466187  .2492000013589859  .032600000500679016            .606964 1 4
          600097 2016  .024205999448895454 0      .47555795135039  9 0  5 3  21.27485466003418   .5242999792098999 .39410001039505005  .005499999970197678            .487187 1 4
          600257 2016    .0175160001963377 0      .11556806488344  5 0  7 2 21.240476608276367  .20340000092983246  .3273000121116638  .004900000058114529            .307518 0 4
          600275 2016  .016947999596595764 0     -.15744931114813  7 0  6 3 19.599491119384766   .5547999739646912 .03590000048279762  -.11640000343322754 .32768200000000003 0 4
             713 2016  .028270000591874123 0   .11272865099799001  5 0  7 3 21.452198028564453   .3294000029563904   .595300018787384  .011300000362098217 .48769799999999996 1 5
          601088 2016  .004145999904721975 0      .03194967191068  9 0  7 3  27.07181739807129   .3353999853134155  1.836899995803833   .05249999836087227            .935463 1 6
          600403 2016    .0365540012717247 0    -.064609154817398 11 0  9 4 23.402080535888672   .5440999865531921  1.069000005722046   -.1370999962091446            .916103 1 6
          601101 2016   .03633899986743927 0  .021287693523675003 15 0 10 5 23.730552673339844   .4593999981880188 2.5239999294281006 .0006000000284984708             .75154 1 6
             937 2016  .010088000446557999 0     .068993326155395  9 0 12 3 24.496410369873047   .5382999777793884 1.8272000551223755  .003800000064074993  .7444700000000001 1 6
             983 2016 .0043680001981556416 0     .031611978794265  9 0  4 3 24.710065841674805   .6402999758720398  2.021199941635132  .008500000461935997            .663494 1 6
          600758 2016   .03842199966311455 0    -.074225751506356  9 0  7 3 23.532129287719727   .6894000172615051  1.153499960899353  .010099999606609344            .237641 1 6
            2128 2016  .010634999722242355 0   -.0043196927435033 12 0 18 4 23.358823776245117   .3149999976158142  .9926000237464905   .05900000035762787  .7083839999999999 1 6
          600188 2016  .017503999173641205 0      .10056235938912 11 0 13 4 25.704280853271484    .649399995803833  3.518899917602539  .016100000590085983            .922232 1 6
          601918 2016  .013260000385344028 0     .022541976409165  9 0  9 3 24.170486450195313   .8443999886512756 2.5690999031066895  .009200000204145908            .500239 1 6
             552 2016  .017326999455690384 0 -.023340799126454002 15 0  8 5 22.925090789794922   .3050999939441681 1.0430999994277954  .024299999698996544  .5880259999999999 1 6
          600971 2016  .018743999302387238 0      .04423356106565 11 0 10 4 23.329391479492188   .5723999738693237 2.1605000495910645  .003000000026077032            .632244 1 6
          601666 2016  .019222000613808632 0     .094928280654406 15 0 14 5 24.364540100097656   .6969000101089478 3.3169000148773193  .019300000742077827            .620344 1 6
          600123 2016  .007600000128149986 0     .015682466795945  8 0  7 3  23.90552520751953   .6092000007629395  2.624000072479248  -.03759999945759773            .543854 1 6
          601001 2016   .01298299990594387 0    -.006363884865345 15 0 10 5  23.99180793762207   .6171000003814697  2.569200038909912  .017400000244379044            .626814 1 6
          601225 2016  .014697999693453312 0    -.022232109255802  7 0  5 3 25.263248443603516   .5242999792098999 1.9316999912261963  .047600001096725464            .721711 1 6
          600508 2016   .01969899982213974 0     .023341773518573  5 0  6 2 23.361570358276367  .36079999804496765 1.7824000120162964  .029899999499320984            .643188 1 6
          600395 2016  .009802999906241894 0   .11009541920027999  3 0 10 2 23.166343688964844  .43860000371932983  .8615999817848206  .017899999395012856            .762187 1 6
          601699 2016  .006833000108599663 0      .14230462456621 17 0  6 6 24.780662536621094   .6891000270843506   2.40120005607605  .013100000098347664            .732817 1 6
          600121 2016  .028516000136733055 0     .013595827790393  9 0  8 3 23.092405319213867   .6528000235557556   1.93149995803833 -.051100000739097595            .674063 1 6
          601898 2016  .014770000241696835 0 -.058731029023690005  8 0  5 3 26.211580276489258   .5784000158309937 3.6263999938964844  .011800000444054604            .886443 1 6
          600348 2016   .00894199963659048 0      .23567497626893  9 0 11 3 24.455995559692383   .6643000245094299 2.5820999145507813  .012000000104308128  .6433570000000001 1 6
             780 2016  .021421000361442566 0    -.065826021612399  7 0  7 3  22.39263153076172   .2304999977350235  .8946999907493591  -.05889999866485596             .63225 1 6
          600397 2016  .019531000405550003 0     -.32816075407342  7 0 12 3 22.717308044433594   .8101999759674072 1.4378999471664429  -.23520000278949738            .441921 1 6
          600985 2016  .032590001821517944 0      .30769520852224  8 0  9 3 21.461986541748047   .3587999939918518  .5340999960899353  .050599999725818634 .41938400000000003 1 6
          300483 2016   .03170499950647354 0    -.079983593266807  7 1  6 3 20.044328689575195   .2167000025510788 .14790000021457672  .026900000870227814            .035266 0 7
             968 2016   .02973099984228611 0    -.089710086182515  9 0  9 3 22.552021026611328   .7613000273704529 1.1675000190734863   .04050000011920929             .10291 1 7
          600759 2016  .009933000430464745 0      .22405736091344  7 0 18 3 23.578340530395508   .6489999890327454  .7817000150680542  .002199999988079071  .5592860000000001 0 7
          600777 2016  .011719999834895134 0   .17419579351311998  7 0 20 3 22.528776168823242  .10270000249147415 .37439998984336853  -.03420000150799751 .26208200000000004 0 7
          600256 2016   .00911100022494793 0  .060233901143482996 11 0  8 4 24.492172241210938   .6998999714851379 1.7770999670028687 .0034000000450760126              .5941 0 7
          600028 2016  .001930000027641654 0     .035474424916463 10 0  6 4 28.035558700561523  .44449999928474426 2.3324999809265137   .04019999876618385            .940971 1 7
          601857 2016  .003022999968379736 0    .0011929356157277 13 0  7 4 28.505218505859375  .42719998955726624  1.716599941253662  .012299999594688416            .986228 1 7
             762 2016  .004885000176727772 0      .21602650653076  7 0  9 4 21.795381546020508  .14149999618530273  .3294000029563904  .021299999207258224            .287271 1 8
             923 2016   .04569799825549126 0      2.7568535306704  9 0 10 3  21.06624984741211   .7105000019073486  .2971999943256378  .001500000013038516            .466051 1 8
          601969 2016  .041384000331163406 0      .10411223539486  9 0 16 4 22.576677322387695   .3686000108718872  .2793000042438507 -.046799998730421066  .8459340000000001 0 8
             655 2016  .019960999488830566 0     -.12458249837082  9 0  6 3 21.822790145874023  .12559999525547028  .5325999855995178  -.17710000276565552             .61487 1 8
          601958 2016  .015564999543130398 0    -.028183091951353 10 0  7 4  23.48796844482422  .18129999935626984  .6431000232696533   .00419999985024333            .802028 1 9
             693 2016  .025848999619483948 0     -.30092829909078  7 0 13 3 22.060766220092773    .776199996471405   .560699999332428  -.08749999850988388            .087879 0 9
          600259 2016   .00837399996817112 0      .35143212949513  9 0 13 4 22.211977005004883   .5236999988555908  .3456000089645386 .0024999999441206455            .615447 1 9
          601168 2016  .045478999614715576 0      .12590032160485  7 0  9 3 24.194185256958008   .5906999707221985 1.7238999605178833 .0032999999821186066            .378882 1 9
            2192 2016  .013917000032961369 0    -.046229410329934  6 1  9 2 20.632251739501953   .1340000033378601  .1606999933719635  .016899999231100082 .10362199999999999 0 9
          600311 2016   .02160399965941906 0    -.041069642781213  7 1  6 3 20.663898468017578  .12229999899864197 .18700000643730164  -.06750000268220901 .18903099999999998 0 9
             758 2016 .0067449999041855335 0     .038708027722616  9 0 25 3 23.890201568603516   .7200000286102295 1.5083999633789063  .014700000174343586 .48192300000000005 1 9
          600338 2016   .01896500028669834 0      .61289738163611  8 0  8 4 21.389707565307617   .3330000042915344 .10289999842643738   .41040000319480896  .5644939999999999 0 9
             426 2016  .010866000317037106 0      .49220659380393  9 0 17 3 23.001842498779297   .5015000104904175   .646399974822998  .012900000438094139            .634928 0 9
          601899 2016 .0035290000960230827 0     .063203571238218 11 0 24 4 25.214345932006836    .651199996471405 1.3596999645233154  .019500000402331352             .52245 1 9
          600489 2016 .0032339999452233315 0  .053732420649129004  9 0  9 3 24.380823135375977   .6057999730110168   .929099977016449  .012600000016391277             .60084 1 9
          601069 2016  .006360999774187803 0     .056006686879082  9 0  6 3 21.712217330932617   .3659999966621399  .1889999955892563   .04839999973773956 .14491099999999998 1 9
          600547 2016  .002234000014141202 0      .13019400461229  9 0  6 3 24.068147659301758   .4235999882221222 .41819998621940613   .05130000039935112            .702753 1 9
          600652 2016  .007065999787300825 0  .015353842901615001  9 0 15 3 21.633037567138672  .12620000541210175  .2320999950170517  .047600001096725464            .197362 0 9
             688 2016  .024112999439239502 0     .018363874293264  9 0 12 3 21.394765853881836  .09470000118017197 .19099999964237213   .11999999731779099            .777788 0 9
          600301 2016   .07068999856710434 0      .06622956683251  9 0  9 3  20.68912696838379   .7609000205993652  .3066999912261963 -.020899999886751175 .33898000000000006 1 9
          603993 2016  .007763999979943037 0      1.8472427586429  8 0 18 3   25.2022705078125   .6104999780654907 1.6073999404907227  .017100000753998756            .853477 0 9
          600497 2016   .00814799964427948 0    -.019657809415166 11 0 16 4 24.214664459228516   .6570000052452087 1.0836000442504883   -.0502999983727932            .580465 1 9
             506 2016  .020639000460505486 0   -.0035297499152453  9 0  8 3 21.895410537719727   .5115000009536743  .3165000081062317  .003100000089034438            .279465 0 9
             975 2016   .02617100067436695 0   -.0025055729941562  9 0 11 3 22.311525344848633  .04399999976158142 .28940001130104065   .06019999831914902            .323654 1 9
            2155 2016   .00648100022226572 0      .12968500768797  7 0 12 3 22.593456268310547  .32749998569488525  .4715000092983246  .020099999383091927            .491867 1 9
             603 2016  .012811999768018723 0       .7144669345983  9 0 14 3 21.767473220825195  .06849999725818634 .24089999496936798   .15600000321865082            .337216 0 9
          600711 2016  .012977000325918198 0      .20594031713383  7 0 14 3 23.015573501586914   .5910999774932861  .9417999982833862    .0215000007301569            .314589 0 9
          600988 2016  .006765000056475401 0   .10519356906736001  7 0 11 3 22.069936752319336  .33880001306533813  .3495999872684479   .09269999712705612            .069075 0 9
          end
          I need to perform placebo test. I saw many papers use placebo they mention something like running the regression 1000 times to estimate the coefficient of placebo and compare it with the coefficient of IV from the main regression model.

          Comment


          • #6
            Thank you for the updated data example. It is still missing a couple of variables that appear in the regression, but by omitting them from the regression, it is possible to get the code to run.

            It does not produce on my setup with this example data any of the problems you describe in #1. And it does create a non-empty plac_coef matrix. The matrix is not very useful because all of its entries are the same number. This is unsurprising because your loop simply repeats the same regression 1000 times and stores the coefficient in each of the 1000 rows of the matrix. I imagine this is not what you intended to do. Presumably you intended to vary either the regression itself, or perhaps which observations would be in the estimation sample during the loop. Or perhaps the idea was to incorporate placebo_gb and plac_post into the regression in some way, and to get 1000 different results like that would have required putting the code that creates those variables inside the loop, not before it.

            Anyway, as I can't tell specifically what you wanted to do, I can't say anything more specific than that.

            As for still getting that error message about -reg- not being a valid command, I think you need to start with a New do-file and hand-type in all of the code, not just that one line.

            Comment


            • #7
              Originally posted by Clyde Schechter View Post

              It does not produce on my setup with this example data any of the problems you describe in #1. And it does create a non-empty plac_coef matrix. The matrix is not very useful because all of its entries are the same number. This is unsurprising because your loop simply repeats the same regression 1000 times and stores the coefficient in each of the 1000 rows of the matrix. I imagine this is not what you intended to do.
              Thank you very much for you detailed response.
              I do understand that the matrix command is working with you. that is good
              but, You mentioned that the 1000 regression would give the same coefficient. actually it is true becuse no new variables added to the model.
              Anyway I am just trying to follow some studies with this test.

              I want to mitigate the potential influence of unobserved factors on my main results using a placebo analysis by re-estimating my baseline regression based on randomly selected firms.
              Hope you could help (DV= SL and IV=gb).


              Comment


              • #8
                I'd like to help, but I still don't have a clear sense of what you want to do. Simply selecting random firms, which is somewhat like what your code does, is not a placebo test. It's actually just a version of bootstrapping. For a placebo test you replace the IV with a variable that is randomized. Or, if you are dealing with a DID scenario, replacing the time of onset with a randomly selected time. There are other variants of placebo testing as well, where the IV and time variables are modified not at random but systematically in ways that target particular forms of confounding.
                On top of that, your example data does not lend itself to manipulations of the time variable because all observations have year == 2016.

                Added: Perhaps this will help. Below is an toy example using the Stata website's grunfeld data set. I first test an "intervention" that affects companies 1 through 5 starting in year 1942. I then do 25 randomized placebo tests, collecting the results in a frame. Maybe you can use this as a model and adapt it to your own situation.
                Code:
                clear*
                webuse grunfeld
                
                //    ANALYZE A "TREATMENT" OCCURRING IN 1942 APPLIED TO COMPANIES 1-5
                gen byte treatment = (company <= 5)
                gen byte post = (year > 1942)
                regress mvalue i.treatment##i.post
                
                //    NOW DO 25 "PLACEBO" RUNS
                set seed 1234
                summ year, meanonly
                local first_year `r(min)'
                local last_year = r(max) - 1
                
                summ company, meanonly
                local first_company `r(min)'
                local last_company `r(max)'
                gen double shuffle = .
                
                frame create results int run_um float(coef se)
                forvalues i = 1/25 {
                    local placebo_year = runiformint(`first_year', `last_year')
                    replace post = (year > `last_year')
                    
                    sort company year
                    by company: replace shuffle = runiform() if _n == 1
                    by company: replace shuffle = shuffle[1]
                    sort shuffle year
                    replace treatment = _n <= _N/2
                    regress mvalue i.treatment##i.post
                    frame post results (`i') (_b[1.treatment#1.post]) (_se[1.treatment#1.post])
                }
                
                frame results: list, noobs clean
                Again, to be clear, I would not ordinarily do a placebo test with this kind of complete randomization of treatment group and time of intervention. If I were concerned about collateral effects of other influences active in 1942, I would keep the original treatment group and see what happens with random placebo years. (Actually, I probably wouldn't randomize year either; I'd try each year once.) Or if I were concerned that other factors common to the original treatment group were a concern, I'd probably keep the year fixed at 1942 but try random subsets of companies as the placebo treatment groups. The code above randomizes both treatment group an year: I did this primarily to show you how one could code both of those randomizations, as it isn't clear to me which one you really need, or if, peculiarly, you really do need to randomize both.
                Last edited by Clyde Schechter; Yesterday, 09:27.

                Comment

                Working...
                X