Announcement

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

  • R2000 no observation error when estimating expected return

    Dear Statalist,

    I'd really appreciate any help members have to offer with my problem.

    I'm running an event study on the princeton method (http://dss.princeton.edu/online_help...ventstudy.html). I've successfully merged my market data , with 316 events over 8 years.
    My event window is (-5;-2) and estimation window is (-205;-6)
    Everything went quite well until the step of calculating expected return

    I used the following code and got r2000 no observation error. Therefore, I am unable to process with calculating CAR.

    Code:
     forvalues i=1(1)284 {
      2. l id company_id if id==`i' & dif==0
      3. reg ret market_return if id==`i' & estimation_window==1
      4. predict p if id==`i'
      5. replace predicted_return = p if id==`i' & event_window==1
      6. drop p
      7. 
    . }
    Here an example of my data

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(company_id date) str17 ret double market_return float set int event_date float(event_id group_id datenum td dif event_window count_event_obs estimation_window count_est_obs id)
    1 18263 "226.06"             518.13 1 20670 1 1   1 1720 -1719 0 4 0 199 1
    1 18266 "221.25"             517.05 1 20670 1 1   2 1720 -1718 0 4 0 199 1
    1 18267 "222.22"             532.53 1 20670 1 1   3 1720 -1717 0 4 0 199 1
    1 18268 "219.33"             534.46 1 20670 1 1   4 1720 -1716 0 4 0 199 1
    1 18269 "219.33"             533.34 1 20670 1 1   5 1720 -1715 0 4 0 199 1
    1 18270 "218.37"              520.9 1 20670 1 1   6 1720 -1714 0 4 0 199 1
    1 18273 "225.1"              515.06 1 20670 1 1   7 1720 -1713 0 4 0 199 1
    1 18274 "223.18"             498.31 1 20670 1 1   8 1720 -1712 0 4 0 199 1
    1 18275 "223.18"             508.61 1 20670 1 1   9 1720 -1711 0 4 0 199 1
    1 18276 "222.22"             512.33 1 20670 1 1  10 1720 -1710 0 4 0 199 1
    1 18277 "219.33"             505.42 1 20670 1 1  11 1720 -1709 0 4 0 199 1
    1 18280 "219.33"             487.13 1 20670 1 1  12 1720 -1708 0 4 0 199 1
    1 18281 "217.41"             495.51 1 20670 1 1  13 1720 -1707 0 4 0 199 1
    1 18282 "218.37"              489.5 1 20670 1 1  14 1720 -1706 0 4 0 199 1
    1 18283 "217.41"             478.42 1 20670 1 1  15 1720 -1705 0 4 0 199 1
    1 18284 "217.41"             477.59 1 20670 1 1  16 1720 -1704 0 4 0 199 1
    1 18287 "214.52"             480.91 1 20670 1 1  17 1720 -1703 0 4 0 199 1
    1 18288 "213.56"              497.9 1 20670 1 1  18 1720 -1702 0 4 0 199 1
    1 18289 "213.56"             486.41 1 20670 1 1  19 1720 -1701 0 4 0 199 1
    1 18290 "215.48"             481.76 1 20670 1 1  20 1720 -1700 0 4 0 199 1
    1 18291 "213.56"             481.96 1 20670 1 1  21 1720 -1699 0 4 0 199 1
    1 18294 "210.67"             486.95 1 20670 1 1  22 1720 -1698 0 4 0 199 1
    1 18295 "208.75"             487.93 1 20670 1 1  23 1720 -1697 0 4 0 199 1
    1 18296 "211.63"             495.48 1 20670 1 1  24 1720 -1696 0 4 0 199 1
    1 18297 "211.63"             503.83 1 20670 1 1  25 1720 -1695 0 4 0 199 1
    1 18298 "208.75"             493.04 1 20670 1 1  26 1720 -1694 0 4 0 199 1
    1 18301 "212.6"               491.2 1 20670 1 1  27 1720 -1693 0 4 0 199 1
    1 18302 "208.75"             482.89 1 20670 1 1  28 1720 -1692 0 4 0 199 1
    1 18303 "207.79"             490.91 1 20670 1 1  29 1720 -1691 0 4 0 199 1
    1 18304 "208.75"             499.94 1 20670 1 1  30 1720 -1690 0 4 0 199 1
    1 18305 "208.75"                507 1 20670 1 1  31 1720 -1689 0 4 0 199 1
    1 18308 "208.75"             507.72 1 20670 1 1  32 1720 -1688 0 4 0 199 1
    1 18309 "209.71" 508.44000000000005 1 20670 1 1  33 1720 -1687 0 4 0 199 1
    1 18310 "211.63"  509.1600000000001 1 20670 1 1  34 1720 -1686 0 4 0 199 1
    1 18311 "210.67"  509.8800000000001 1 20670 1 1  35 1720 -1685 0 4 0 199 1
    1 18312 "213.56" 510.60000000000014 1 20670 1 1  36 1720 -1684 0 4 0 199 1
    1 18315 "213.56"             510.02 1 20670 1 1  37 1720 -1683 0 4 0 199 1
    1 18316 "217.41"             496.29 1 20670 1 1  38 1720 -1682 0 4 0 199 1
    1 18317 "215.48"             494.59 1 20670 1 1  39 1720 -1681 0 4 0 199 1
    1 18318 "217.41"             494.99 1 20670 1 1  40 1720 -1680 0 4 0 199 1
    1 18319 "217.41"             496.91 1 20670 1 1  41 1720 -1679 0 4 0 199 1
    1 18322 "217.41"             503.01 1 20670 1 1  42 1720 -1678 0 4 0 199 1
    1 18323 "223.18"                501 1 20670 1 1  43 1720 -1677 0 4 0 199 1
    1 18324 "223.18"             507.32 1 20670 1 1  44 1720 -1676 0 4 0 199 1
    1 18325 "225.1"              511.91 1 20670 1 1  45 1720 -1675 0 4 0 199 1
    1 18326 "224.14"             513.39 1 20670 1 1  46 1720 -1674 0 4 0 199 1
    1 18329 "222.22"             521.12 1 20670 1 1  47 1720 -1673 0 4 0 199 1
    1 18330 "221.25"             527.27 1 20670 1 1  48 1720 -1672 0 4 0 199 1
    1 18331 "223.18"             525.67 1 20670 1 1  49 1720 -1671 0 4 0 199 1
    1 18332 "216.44"             524.64 1 20670 1 1  50 1720 -1670 0 4 0 199 1
    1 18333 "220.29"             531.51 1 20670 1 1  51 1720 -1669 0 4 0 199 1
    1 18336 "220.29"             531.86 1 20670 1 1  52 1720 -1668 0 4 0 199 1
    1 18337 "220.29"             516.08 1 20670 1 1  53 1720 -1667 0 4 0 199 1
    1 18338 "221.25"             510.85 1 20670 1 1  54 1720 -1666 0 4 0 199 1
    1 18339 "221.25"             519.73 1 20670 1 1  55 1720 -1665 0 4 0 199 1
    1 18340 "221.25"             515.99 1 20670 1 1  56 1720 -1664 0 4 0 199 1
    1 18343 "221.25"             511.58 1 20670 1 1  57 1720 -1663 0 4 0 199 1
    1 18344 "221.25"             506.53 1 20670 1 1  58 1720 -1662 0 4 0 199 1
    1 18345 "222.22"             512.12 1 20670 1 1  59 1720 -1661 0 4 0 199 1
    1 18346 "222.22"             503.39 1 20670 1 1  60 1720 -1660 0 4 0 199 1
    1 18347 "219.33"              505.3 1 20670 1 1  61 1720 -1659 0 4 0 199 1
    1 18350 "218.37"             505.67 1 20670 1 1  62 1720 -1658 0 4 0 199 1
    1 18351 "224.14"             500.72 1 20670 1 1  63 1720 -1657 0 4 0 199 1
    1 18352 "221.25"             499.24 1 20670 1 1  64 1720 -1656 0 4 0 199 1
    1 18353 "224.14"             508.18 1 20670 1 1  65 1720 -1655 0 4 0 199 1
    1 18354 "224.14"             510.48 1 20670 1 1  66 1720 -1654 0 4 0 199 1
    1 18357 "226.06"             514.79 1 20670 1 1  67 1720 -1653 0 4 0 199 1
    1 18358 "226.06"             515.33 1 20670 1 1  68 1720 -1652 0 4 0 199 1
    1 18359 "223.18"             515.82 1 20670 1 1  69 1720 -1651 0 4 0 199 1
    1 18360 "218.37"             515.93 1 20670 1 1  70 1720 -1650 0 4 0 199 1
    1 18361 "217.41"             517.42 1 20670 1 1  71 1720 -1649 0 4 0 199 1
    1 18364 "213.56"             519.93 1 20670 1 1  72 1720 -1648 0 4 0 199 1
    1 18365 "213.56"             517.98 1 20670 1 1  73 1720 -1647 0 4 0 199 1
    1 18366 "213.56"             516.21 1 20670 1 1  74 1720 -1646 0 4 0 199 1
    1 18367 "213.56"             521.49 1 20670 1 1  75 1720 -1645 0 4 0 199 1
    1 18368 "208.75"             522.03 1 20670 1 1  76 1720 -1644 0 4 0 199 1
    1 18371 "197.2"              516.74 1 20670 1 1  77 1720 -1643 0 4 0 199 1
    1 18372 "206.82"              515.2 1 20670 1 1  78 1720 -1642 0 4 0 199 1
    1 18373 "207.79"              519.7 1 20670 1 1  79 1720 -1641 0 4 0 199 1
    1 18374 "208.75"             529.31 1 20670 1 1  80 1720 -1640 0 4 0 199 1
    1 18375 "209.71"  530.7099999999999 1 20670 1 1  81 1720 -1639 0 4 0 199 1
    1 18378 "208.75"             531.21 1 20670 1 1  82 1720 -1638 0 4 0 199 1
    1 18379 "210.67"             535.72 1 20670 1 1  83 1720 -1637 0 4 0 199 1
    1 18380 "203.94"              539.2 1 20670 1 1  84 1720 -1636 0 4 0 199 1
    1 18381 "205.86"             542.37 1 20670 1 1  85 1720 -1635 0 4 0 199 1
    1 18382 "206.82"             545.37 1 20670 1 1  86 1720 -1634 0 4 0 199 1
    1 18385 "206.82"             545.51 1 20670 1 1  87 1720 -1633 0 4 0 199 1
    1 18386 "208.75"             549.12 1 20670 1 1  88 1720 -1632 0 4 0 199 1
    1 18387 "208.75"             548.01 1 20670 1 1  89 1720 -1631 0 4 0 199 1
    1 18388 "206.82"             549.51 1 20670 1 1  90 1720 -1630 0 4 0 199 1
    1 18389 "203.94"             542.03 1 20670 1 1  91 1720 -1629 0 4 0 199 1
    1 18392 "204.9"              534.38 1 20670 1 1  92 1720 -1628 0 4 0 199 1
    1 18393 "202.01"             534.36 1 20670 1 1  93 1720 -1627 0 4 0 199 1
    1 18394 "203.94"              519.6 1 20670 1 1  94 1720 -1626 0 4 0 199 1
    1 18395 "202.01"             518.93 1 20670 1 1  95 1720 -1625 0 4 0 199 1
    1 18396 "202.01"             520.72 1 20670 1 1  96 1720 -1624 0 4 0 199 1
    1 18399 "200.09"             511.27 1 20670 1 1  97 1720 -1623 0 4 0 199 1
    1 18400 "202.01"              508.3 1 20670 1 1  98 1720 -1622 0 4 0 199 1
    1 18401 "201.05"              494.9 1 20670 1 1  99 1720 -1621 0 4 0 199 1
    1 18402 "201.05"             503.55 1 20670 1 1 100 1720 -1620 0 4 0 199 1
    end
    format %tdnn/dd/CCYY date
    format %tdnn/dd/CCYY event_date
    Thank you in advance

  • #2
    Crucial error here is that your variable ret is string.
    Code:
    destring ret, replace
    but make sure you understand why it is string

    Apart from that, the selections you have in your loop also mean that no observations satisfy your conditions, i.e. in your example diff is never 0, and event_window is never 1. This may be different fro the rest of your dataset, but could be another reason why you would get 'no observations' error even after destringing ret

    Comment


    • #3
      Originally posted by Jorrit Gosens View Post
      Crucial error here is that your variable ret is string.
      Code:
      destring ret, replace
      but make sure you understand why it is string

      Apart from that, the selections you have in your loop also mean that no observations satisfy your conditions, i.e. in your example diff is never 0, and event_window is never 1. This may be different fro the rest of your dataset, but could be another reason why you would get 'no observations' error even after destringing ret

      Hi, thank you very much for your help

      I tried the destring command as you suggested and got the following result

      Code:
      ret contains nonnumeric characters; no replace
      For the second problem you mentioned, this is only a small example of my data, in the rest, there is 0 diff and 1 event_window
      I really don't know what the problem is

      Comment


      • #4
        The first problem to address is still destringing the variable ret.
        do:
        Code:
        clonevar ret_copy = ret
        destring ret, replace force
        Your result "ret contains nonnumeric characters; no replace" means that ret has some text values for some observations. Stata therefore treats all values as text, you can notice this from them being displayed in red color rather than black in the data editor screen.
        You can use destring to convert text to numeric, but the observations with text values would be lost when destringing, and Stata will not throw them away unless specifically asked to do so.

        The above code first makes a copy of your ret variale, and then tells Stata to destring the ret variable, including setting observations with text (maybe n/a or ?) to missing.

        Again, before you destring force (especially when using force option), you might want to investigate why the ret variable is a string and not numeric

        Comment


        • #5
          Originally posted by Jorrit Gosens View Post
          The first problem to address is still destringing the variable ret.
          do:
          Code:
          clonevar ret_copy = ret
          destring ret, replace force
          Your result "ret contains nonnumeric characters; no replace" means that ret has some text values for some observations. Stata therefore treats all values as text, you can notice this from them being displayed in red color rather than black in the data editor screen.
          You can use destring to convert text to numeric, but the observations with text values would be lost when destringing, and Stata will not throw them away unless specifically asked to do so.

          The above code first makes a copy of your ret variale, and then tells Stata to destring the ret variable, including setting observations with text (maybe n/a or ?) to missing.

          Again, before you destring force (especially when using force option), you might want to investigate why the ret variable is a string and not numeric
          Thanks so much for your help

          I will try the code you suggested

          Comment


          • #6
            Originally posted by Jorrit Gosens View Post
            The first problem to address is still destringing the variable ret.
            do:
            Code:
            clonevar ret_copy = ret
            destring ret, replace force
            Your result "ret contains nonnumeric characters; no replace" means that ret has some text values for some observations. Stata therefore treats all values as text, you can notice this from them being displayed in red color rather than black in the data editor screen.
            You can use destring to convert text to numeric, but the observations with text values would be lost when destringing, and Stata will not throw them away unless specifically asked to do so.

            The above code first makes a copy of your ret variale, and then tells Stata to destring the ret variable, including setting observations with text (maybe n/a or ?) to missing.

            Again, before you destring force (especially when using force option), you might want to investigate why the ret variable is a string and not numeric
            Hi

            I tried the code you suggested and it work perfectly fine destringing my ret
            However, I used the following code to calculate the expected return, I encountered another problem

            Code:
             forvalues i=1(1)284 {
              2. l id company_id if id==`i' & dif==0
              3. reg ret market_return if id==`i' & estimation_window==1
              4. predict p if id==`i'
              5. replace predicted_return = p if id==`i' & event_window==1
              6. drop p
              7. 
            . }
            the result I received is as following and stata only gives expected return for 1 out of 284 companies in my data set

            Code:
             
            variable predicted_return not found

            Comment


            • #7
              Means what it says. You try to replace predicted_return but you need to generate a variable before you can replace it.

              Comment


              • #8
                Originally posted by Nick Cox View Post
                Means what it says. You try to replace predicted_return but you need to generate a variable before you can replace it.

                I already did, using the following code
                But Stata only gave expected return for the first company and no results for the rest
                Any suggestion to fix this?
                Thank you very much in advance

                Code:
                gen predicted_return=.
                egen id=group(company_id)
                Last edited by Mai Hang Nguyen; 07 Aug 2018, 15:13.

                Comment


                • #9
                  That's not the code you showed in #6 or indeed in #1.

                  Further, if such a variable did exist, then the error message would not have occurred. We have not a hope of knowing for sure what you do not show us nor a reason not to make inferences based on what you do show us.

                  Yet further, your example data covers the first company only, so we are in the dark on what is happening for other companies.

                  I suggest that you try again with your data for company 2 and the complete code you are now using.


                  Comment

                  Working...
                  X