Announcement

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

  • How to generate these following month variables?

    Hi all,

    I have the following equation:
    Click image for larger version

Name:	Screenshot 2024-07-14 at 13.23.25.png
Views:	1
Size:	20.5 KB
ID:	1758662

    where D is a dummy variable which equals 1 if an individual was born in December and 0 if he/she was born in January of the following year; Z is the month of birth, sorted for a time window from February of a year to November of the following year; c is the threshold at January in that window; and I is a dummy variable indicating whether the individual was born from January onward.

    I want to generate the following variables: D, Z, c, and I. I would greatly appreciate it if anyone could help me out. For simplicity, please ignore subscripts i and j for now. Thanks!

    Data example
    Code:
    clear
    input byte month int year
     1 2016
     8 2017
     8 2018
     2 2016
     3 2017
     8 2019
     7 2017
     8 2016
     11 2020
     4 2018
     8 2018
    10 2017
     9 2020
     7 2019
     8 2020
    11 2019
     2 2016
     5 2019
     5 2020
     5 2018
     3 2017
     6 2017
     3 2016
     1 2020
     1 2020
    11 2019
    11 2015
    11 2015
     7 2015
    10 2019
     1 2020
     6 2016
     9 2015
     1 2016
    12 2019
     3 2020
    11 2020
    11 2015
    12 2015
    12 2017
     4 2020
     3 2020
     2 2019
     7 2020
    10 2017
     7 2019
     8 2020
     8 2018
     4 2019
    12 2019
     8 2018
     4 2017
     5 2018
     7 2017
     6 2017
     3 2016
     9 2018
     9 2017
     3 2015
     4 2018
     5 2017
     5 2016
     1 2016
    11 2016
     8 2019
     7 2019
     1 2016
     5 2019
    10 2017
    10 2015
     7 2020
    10 2016
     9 2016
     7 2020
     2 2020
    12 2015
     2 2019
     7 2018
     6 2020
     4 2016
     6 2016
    10 2019
     3 2017
    12 2017
    12 2018
     2 2017
     6 2019
     6 2019
     4 2017
     3 2018
     2 2017
     9 2020
    12 2015
    12 2016
     9 2017
     9 2018
     9 2016
     7 2018
    end
    label values month labels12
    label def labels12 1 "JANUARY", modify
    label def labels12 2 "FEBRUARY", modify
    label def labels12 3 "MARCH", modify
    label def labels12 4 "APRIL", modify
    label def labels12 5 "MAY", modify
    label def labels12 6 "JUNE", modify
    label def labels12 7 "JULY", modify
    label def labels12 8 "AUGUST", modify
    label def labels12 9 "SEPTEMBER", modify
    label def labels12 10 "OCTOBER", modify
    label def labels12 11 "NOVEMBER", modify
    label def labels12 12 "DECEMBER", modify
    label values year labels13

  • #2
    Hello, is there anyone who can help me with the issue in #1? Thank you.

    Comment


    • #3
      While I can only truly speak for myself, given that it has gone unanswered for about 48 hours, I think it likely that others have had the same reaction to #1 as I did. I read it several time, and found myself unable to figure out what you want to do, or how it relates to the example data shown. I think it may remain that way unless you can post a clearer explanation of what the variables you want to create are. Actually, I suspect that to truly make it clear, it would be best to show worked, annotated examples of several observations from your data set, showing at least one example for all of the cases that might arise.

      Comment


      • #4
        Dear Prof. Clyde,

        Thank you for your reply and I am sorry for the lack of information. Let's me try explaining it again.

        Given the data example in #1, I want to generate a variable D which equals 1 if an individual was born in December and 0 if he/she was born in January of the following year. I think your code in other thread can do it well
        Code:
        gen D = 12.month
        I also want to create variable Z which contain a set of months, ranging from February of a given year to November of the following year. It means this variable consists of 22 months in two contiguous years. I hope that this time will be much clearer. Thank you!

        Comment


        • #5
          I also want to create variable Z which contain a set of months, ranging from February of a given year to November of the following year. It means this variable consists of 22 months in two contiguous years. I hope that this time will be much clearer.
          Sorry, but I don't understand this at all.

          Variables in Stata contain either numbers or strings, not sets. You might represent a set of months by a string containing the names of the months, or by a number that in some way encodes the particular months in the set. But in any of the observations in your data set, which months would be long to the set of months that you want to represent in that observation. And do you have some preferred way of representing a set of months as a string, or as a number? Perhaps you can show what this variable would look like in the first five observations of your example data shown in #1.

          Comment


          • #6
            Hello Matthew,

            I have to admit that, like Clyde, I don't really understand what you actually want. It would help us a lot if you could generate, say, 30 observations that correspond to your data and then manually (for example via the Stata data editor) the variables for which you need a generation syntax so that we can even imagine what your goal is.

            Comment


            • #7
              I align myself with Clyde Schechter and Benno Schoenberger

              We're all volunteers here -- even StataCorp employees -- and there is some caprice about what gets answered, even if minimally with "This isn't clear to me".

              I tried reading this a few times and couldn't get past the dummy that is 1 for December and 0 for January of the following year; what is the point to "of the following year" and what happens for the other 10 months?

              So, now #3 #5 #6 and this post are all calls for a better data example and more clarity.

              Comment

              Working...
              X