Announcement

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

  • Splitting Year

    Dear, I am quite new to STATA and I need t seprate the year from tthe months and days, i.e. right now I have
    "Dec 2007" and "19 Oct 2011" and i only want "2007" and "2011".
    Please let me know if there is anyway I can do this in STATA instead of excel as this data is very large.


    Example generated by -dataex-. To install: ssc install dataex
    clear
    str11 year int directorid double linkeddirectorid
    "1971" 14010 411635791
    "Dec 2007" 14010 94080412469
    "Mar 2013" 14010 452529652
    "1973" 14010 1595108021
    "Apr 1998" 14010 14466297812
    "2010" 14010 14480197833
    "1979" 14010 2290573059
    "19 Oct 2011" 14010 11852194451
    "Nov 2000" 14010 51980411846
    "Feb 1986" 14010 3581626766
    "08 Sep 2009" 14010 3558236484
    "Jul 2000" 14010 4625210406
    "Jul 1994" 14010 629144854
    "May 2006" 14010 13645736920
    "2008" 14010 94083412476
    "1989" 14010 438448496
    "Feb 1986" 14010 12603255609
    "2011" 14010 11963444640
    "1979" 14010 2250571912
    "Mar 2014" 14010 14311977652
    "18 Feb 2004" 14010 2257272132
    "1979" 14010 4583910103
    "1991" 14010 632365304

    Kind Regards
    Jas


  • #2
    Jaskaran:
    maybe what follows can help:
    Code:
    . set obs 1
    
    . g A="Dec 2007"
    
    . split A, destring
    
    . keep A2
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Dear Carlo,

      It Worked!!Thank you so much.

      Is there any command i can use to keep year between 2005 and 2016 in the above provided example?

      Regards
      Jas
      Last edited by jaskaran kaur; 10 Dec 2018, 08:21.

      Comment


      • #4
        What's true of all your examples is that

        Code:
        gen wanted = real(word(year, -1))
        would give you what you want. Then

        Code:
        keep if inrange(wanted, 2005, 2016)
        may help further.

        Comment


        • #5
          Thank you so much Nick. That command worked perfectly.

          Regards
          Jaskaran

          Comment

          Working...
          X