Announcement

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

  • Generating weeks from date

    I want to create a variable, "ymw," where y refers to the year, m refers to months, and w refers to the week. I have date data available from 5th April 1996.

    Data ex-

    input str66 CompanyName str10 Date str9 MarketCapitalization double Returns
    "20Th Century Finance Corpn. Ltd. [Merged]" "05-04-1996" "821.10" 0
    "3M India Ltd." "05-04-1996" "1915.06" 1.49
    "3P Land Holdings Ltd." "05-04-1996" "238.50" -1.85
    "63 Moons Technologies Ltd." "05-04-1996" "66.00" -4.35
    "A B B India Ltd." "05-04-1996" "19104.22" 0
    "A B C Bearings Ltd. [Merged]" "05-04-1996" "418.97" -3.33
    "A B C Gas (International) Ltd." "05-04-1996" "5.94" 9.09
    "A B C India Ltd." "05-04-1996" "74.03" 2.78
    "A B N Granites Ltd." "05-04-1996" "25.97" 7.69
    "A C C Ltd." "05-04-1996" "34253.07" 3.23
    "A C E Edutrend Ltd." "04-04-1996" "28.45" -2.7
    "A C E Laboratories Ltd." "05-04-1996" "156.57" 0
    "A C I Infocom Ltd." "05-04-1996" "79.21" 0
    "A D C India Communications Ltd." "04-04-1996" "322.00" 0
    "A D F Foods Ltd." "05-04-1996" "280.28" 1.96
    "A D M Agro Inds. Latur & Vizag Pvt. Ltd." "04-04-1996" "159.43" 16.67
    "A E C (India) Ltd." "05-04-1996" "170.87" 0
    "A E C Enterprises Ltd." "05-04-1996" "256.90" 6.25
    "A G I Greenpac Ltd." "05-04-1996" "922.40" -2.13
    "A J Brothers Ltd." "04-04-1996" "49.27" 0
    "A K C Synthetics Ltd." "05-04-1996" "5.28" -21.43
    "A K G Acoustics (India) Ltd." "05-04-1996" "143.79" 4.17
    "A K S Credits Ltd." "05-04-1996" "66.31" -1.45
    "A M I Computers (I) Ltd." "04-04-1996" "39.81" -7.14
    "A M J Land Holdings Ltd." "05-04-1996" "869.20" 0
    "A N G Industries Ltd." "05-04-1996" "28.52" -25
    "A P M Industries Ltd." "05-04-1996" "82.12" -5
    "A P T Packaging Ltd." "05-04-1996" "0.00" 0
    "A S I Industries Ltd." "05-04-1996" "286.71" -4.65
    "A S M Technologies Ltd." "04-04-1996" "27.00" -5.26
    "A T N International Ltd." "05-04-1996" "147.82" -1.3
    "A T V Projects India Ltd." "05-04-1996" "1088.91" 5.13
    "A V I Export (India) Ltd." "04-04-1996" "135.77" 0
    "A V I Industries Ltd." "05-04-1996" "104.48" 0
    "A V I Products India Ltd." "05-04-1996" "22.62" 0
    "A V T Natural Products Ltd." "04-04-1996" "22.88" 23.81
    "A Y M Syntex Ltd." "05-04-1996" "158.12" -3.85
    "Aadhya Ceramics Ltd." "05-04-1996" "31.05" 12.5
    "Aadi Industries Ltd." "05-04-1996" "27.54" -8.33
    "Aakar Engineering & Mfg. Co. Ltd." "05-04-1996" "32.50" 0
    "Aankit Granites Ltd." "05-04-1996" "34.69" 6.25
    "Aarey Drugs & Pharmaceuticals Ltd." "05-04-1996" "45.00" 0
    "Aarti Drugs Ltd." "04-04-1996" "127.50" 0
    "20Th Century Finance Corpn. Ltd. [Merged]" "12-04-1996" "821.10" 0
    "3M India Ltd." "12-04-1996" "1915.06" 1.49
    "3P Land Holdings Ltd." "12-04-1996" "238.50" -1.85
    "63 Moons Technologies Ltd." "12-04-1996" "66.00" -4.35
    "A B B India Ltd." "12-04-1996" "19104.22" 0
    "A B C Bearings Ltd. [Merged]" "12-04-1996" "418.97" -3.33
    "A B C Gas (International) Ltd." "12-04-1996" "5.94" 9.09
    "A B C India Ltd." "12-04-1996" "74.03" 2.78
    "A B N Granites Ltd." "12-04-1996" "25.97" 7.69
    "A C C Ltd." "12-04-1996" "34253.07" 3.23
    "A C E Edutrend Ltd." "12-04-1996" "28.45" -2.7
    "A C E Laboratories Ltd." "11-04-1996" "156.57" 0
    "A C I Infocom Ltd." "12-04-1996" "79.21" 0
    "A D C India Communications Ltd." "11-04-1996" "322.00" 0
    "A D F Foods Ltd." "12-04-1996" "280.28" 1.96
    "A D M Agro Inds. Latur & Vizag Pvt. Ltd." "11-04-1996" "159.43" 16.67
    "A E C (India) Ltd." "12-04-1996" "170.87" 0
    "A E C Enterprises Ltd." "12-04-1996" "256.90" 6.25
    "A G I Greenpac Ltd." "12-04-1996" "922.40" -2.13
    "A J Brothers Ltd." "11-04-1996" "49.27" 0
    "A K C Synthetics Ltd." "12-04-1996" "5.28" -21.43
    "A K G Acoustics (India) Ltd." "12-04-1996" "143.79" 4.17
    "A K S Credits Ltd." "12-04-1996" "66.31" -1.45
    "A M I Computers (I) Ltd." "11-04-1996" "39.81" -7.14
    "A M J Land Holdings Ltd." "12-04-1996" "869.20" 0
    "A N G Industries Ltd." "12-04-1996" "28.52" -25
    "A P M Industries Ltd." "12-04-1996" "82.12" -5
    "A P T Packaging Ltd." "12-04-1996" "0.00" 0
    "A S I Industries Ltd." "12-04-1996" "286.71" -4.65
    "A S M Technologies Ltd." "11-04-1996" "27.00" -5.26
    "A T N International Ltd." "12-04-1996" "147.82" -1.3
    "A T V Projects India Ltd." "12-04-1996" "1088.91" 5.13
    "A V I Export (India) Ltd." "11-04-1996" "135.77" 0
    "A V I Industries Ltd." "12-04-1996" "104.48" 0
    "A V I Products India Ltd." "12-04-1996" "22.62" 0
    "A V T Natural Products Ltd." "11-04-1996" "22.88" 23.81
    "A Y M Syntex Ltd." "12-04-1996" "158.12" -3.85
    "Aadhya Ceramics Ltd." "12-04-1996" "31.05" 12.5
    "Aadi Industries Ltd." "12-04-1996" "27.54" -8.33
    "Aakar Engineering & Mfg. Co. Ltd." "12-04-1996" "32.50" 0
    "Aankit Granites Ltd." "12-04-1996" "34.69" 6.25
    "Aarey Drugs & Pharmaceuticals Ltd." "12-04-1996" "45.00" 0
    "Aarti Drugs Ltd." "11-04-1996" "127.50" 0
    end

  • #2
    You need to define what you mean by week. There are many possible definitions.

    1. A week begins on a certain day (e.g. Sunday or Monday) and ends 6 days later. Weeks so defined can cross not just months but also years.

    2. Stata's definition.

    3. ISO weeks.

    4. Any other definition.

    Comment


    • #3
      I have weekly returns data obtained on the last trading day of each week, and the date corresponds to the last trading day of each week for each stock.

      Comment


      • #4
        1. Create a Stata data variable from your date, something like
        Code:
        gen statadate = date(Date,"DMY")
        (I cannot figure out from your data what comes first, the day or the month. If the month comes first then date(Date,"MDY")

        2. Create a year and month variables. See the date functions, they would be probably something like year(statadate) and month(statadate)

        3. Create your week variable from some statement like

        Code:
        sort CompanyName year month statadate
        by CompanyName year month: gen week = _n
        4. Create your new date variable YearMonthWeek from the components you created above. There must be some FAQ on "creating dates from numerical components".

        Comment


        • #5
          Kolev- Thank you for the codes. I was able to generate a week variable. For YearMonthWeek, I tried searching on the Stata list but could not find any code.

          Comment

          Working...
          X