Announcement

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

  • Question on select data for a specific period

    Hi!
    I'm having trouble with data cleaning. My time_var data is in long format (eg. 31may2011) and after I set the time_var to panel data, what command should I use to pick the data for a specific time period. (Example: 01nov2004 - 31may2013). "inrange" code does not work. Can anyone help me with this problem please? Many thanks.

  • #2
    Assuming that your time_var is a true Stata internal format date variable that is being displayed with the %td display format, then the following approach should work:
    Code:
    whatever if inrange(time_var, td(01nov2004), td(31may2013))
    In the future, when asking for help with code, always show example data. Do that using the -dataex- command. 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.

    Also, never say something "doesn't work." There are many, many ways in which something might not work. You always need to show the exact code you tried and show the exact output you got from Stata, and then, unless it is painfully obvious to anybody, explain why what you got is not what you expected.

    Please read the Forum FAQ for a wide range of excellent advice on how to post your queries in ways that maximize your chance of getting a timely and helpful response.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Assuming that your time_var is a true Stata internal format date variable that is being displayed with the %td display format, then the following approach should work:
      Code:
      whatever if inrange(time_var, td(01nov2004), td(31may2013))
      In the future, when asking for help with code, always show example data. Do that using the -dataex- command. 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.

      Also, never say something "doesn't work." There are many, many ways in which something might not work. You always need to show the exact code you tried and show the exact output you got from Stata, and then, unless it is painfully obvious to anybody, explain why what you got is not what you expected.

      Please read the Forum FAQ for a wide range of excellent advice on how to post your queries in ways that maximize your chance of getting a timely and helpful response.
      Thank you very much! It is very useful! Totally solved my problem.

      Comment

      Working...
      X