Announcement

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

  • Problem creating dummy variables that falls within an interval of dates.

    I am trying to create a dummy variable that =1 if an individual's birthday falls within the 99 days that precede the beginning of Ramadan, and =0 otherwise for every year dating back to 1960.

    I’ve had success by converting all the dates into the Julian calendar (uses the numerical value of the date out of 365. For example, January = 0, February = 31, July = 181 and so on. Then add the day for your Julian calendar equivalence. July 31st would be 181 + 31 = 212). From there, I can subtract 99 and obtain the appropriate interval, and birthdays that fall within that interval are set equal to 1.

    However, my problem arrises when the interval falls back into the previous year. For example, January 7th would be 0+7=7. Subtract 99, and I get -92, when it should be 273 of the previous year. Is there a simpler approach that I can be taking?
    Last edited by anthony yamzon; 05 Jul 2022, 12:19.

  • #2
    I do not understand how your dates are recorded in Stata. Do you have separate variables for month and day and year? That seems to be what you describe.

    What you need is for your dates to be stored as Stata "daily" dates, which record the month, day, and year as a single variable, so that when you subtract 99 days from January 7th you get September 30th of the previous year. Also, when you subtract 99 days from March 10, you get a different answer in leap years.

    Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

    All Stata manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

    Comment


    • #3
      Using Statalist is just like making wild mushrooms risotto. If I asked you to make my favorite version of risotto, you'd likely need to know what the SPECIFIC ingredients are and the steps you do to make said dish.

      So far you've neither, you're asking us for help to make something and you've not given the dataset you're dealing with or any code you've tried. EDIT: This entails that you give us an example of your data, using dataex, and the exact code you've tried so far.

      I also echo William Lisowski's comments. I've used Stata since I was 19ish, and I'm 25 now, and lots of the date and time stuff confuses me to this very day, but that's because it's versatile and comprehensive. There's little substitute for reading the help files and really getting intimately familiar with it, ESPECIALLY for date and time settings.

      Comment


      • #4
        Thank you both. This is something I will be looking into.

        Comment

        Working...
        X