Announcement

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

  • Dropping Observations by using if command

    I have the daily return datasets for various companies from 1996 to 2021 (example of dataset attached below)-

    input long co_code str8 co_stkdate float(bse_firm_level_return_percentage nse_firm_level_return_percentage)
    11 "20081006" 0 0
    11 "20081007" -9 -11
    11 "20081008" -13 -12
    11 "20081010" -11 -12
    11 "20081013" 7 6
    11 "20081014" -10 -10
    11 "20081015" 9 10
    11 "20081016" 14 13
    11 "20081017" -20 -20
    11 "20081020" -1 -1
    11 "20081021" -3 0
    11 "20081022" -5 -6
    11 "20081023" -7 -6
    11 "20081024" -13 -14
    11 "20081027" -8 -10
    11 "20081028" 19 20
    11 "20081029" -9 -5
    11 "20081031" 3 4
    11 "20081103" 1 0
    11 "20081104" 8 5
    11 "20081105" -2 0
    11 "20081106" 0 -1
    11 "20081107" 14 15
    11 "20081110" -3 -4

    I want to drop the observations of the companies with zero returns on at least 75% of the days in the last 12 months. Kindly help me in this regard.

  • #2
    I am having difficulty understanding what that means , but I can advise that your date variable is not fit for Stata purposes.


    Code:
    gen ddate = daily(co_stkdate, "YMD")
    format ddate %td

    Comment


    • #3
      Cox: I have used the following command for date:
      tostring co_stkdate, replace force
      list co_stkdate
      gen date2 = date( co_stkdate, "YMD")
      gen cal_year = year(date2)
      gen month= month(date2)
      gen year= cal_year if(month <= 3)
      list year
      replace year = (cal_year + 1) if(month >3)
      list year
      format date2 %td

      Got this output after the following command-
      input long co_code float(date2 cal_year month year bse_firm_level_return_percentage nse_firm_level_return_percentage)
      11 17811 2008 10 2009 0 0
      11 17812 2008 10 2009 -9 -11
      11 17813 2008 10 2009 -13 -12
      11 17815 2008 10 2009 -11 -12
      11 17818 2008 10 2009 7 6
      11 17819 2008 10 2009 -10 -10
      11 17820 2008 10 2009 9 10
      11 17821 2008 10 2009 14 13
      11 17822 2008 10 2009 -20 -20
      11 17825 2008 10 2009 -1 -1
      11 17826 2008 10 2009 -3 0
      11 17827 2008 10 2009 -5 -6
      11 17828 2008 10 2009 -7 -6


      What I mean to ask is that I want to exclude those stocks which had zero returns (calculated as the ratio between today's closing price and the last closing price) on at least 75% of the days in the last 12 months. Eg- a stock is traded for 300 days in a year and for at least 225 days (75% of 300) the returns were 0%. So, I want to drop this stock from my data.

      Comment

      Working...
      X