Announcement

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

  • generate yearly date variable

    Hi,

    very simple question:

    I want to generate a yearly time variable from 1870 - 2017 in my stata spreadsheet. I could not find the code yet.

    many thanks
    C

  • #2
    It's not a very simple question at all. From other existing variables, say daily dates or monthly dates? To correspond to 148 observations which should be thought of as from 1870 to 2017? I can imagine yet other possibilities. So, your question just raises other questions.

    Happy to help but please back up and use dataex. If you don't know what that means, please do read and act on https://www.statalist.org/forums/help#stata

    Comment


    • #3
      I have an empty spreadsheet with 147 empty observations, and want to generate a new variable containing years 1870-2017.

      Why? This would relate to a separate thread, but I was curious about the above question also.
      I have a balanced panel dataset with n=17 and t=147. I want to add an additional cross section to this data-set. My approach was to generate an (almost) empty spreadsheet and 'append' it to the main sheet. Hence, I only want a date var, country_id var, and some empty vars.

      Comment


      • #4
        I am not sure that I understand "an empty spreadsheet with 147 empty observations" which sounds more than an MS Excel worldview, but taking you literally,

        Code:
        gen year = _n + 1869
        would get you dates from 1870 to 2016 (not 2017).

        You may need to go

        Code:
        set obs 148 
        beforehand to get what you want.

        Comment

        Working...
        X