Announcement

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

  • Using tsfill with missing values for date variable

    Dear all,

    I have two different date variables in my dataset, year and month. For some individuals however, the month variable is a missing value.
    It look like this:
    id year month
    1 2015 2015m1
    1 2015 2015m2
    1 2015 2015m3
    2 2015 .
    3 2015 .
    4 2015 .
    I would like to expand the month variable to every individual. But I cannot use tsfill, as I get the error "repeated time values within panel". I think this comes from the missing values,
    Do you know how can I do what I intend using the tsfill command?
    Many thanks.

  • #2
    That's up to you. What makes sense substantively? Just possibly, observations with missing month just have to be ignored, depending on your goals.

    Comment


    • #3
      I'm not entirely sure what you want the result to look like from your description. But perhaps this will at least point you in the right direction:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte id int year float month
      1 2015 660
      1 2015 661
      1 2015 662
      2 2015   .
      3 2015   .
      4 2015   .
      end
      format %tm month
      
      drop year
      fillin id month
      gen year = year(dofm(month))
      In the future, when showing data examples, please use the -dataex- command to do so as I have here. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


      Comment

      Working...
      X