Announcement

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

  • How to compute this faction variable?

    Dear all,

    I am interested in a policy A and its eligibility is: children under the age of 5 at the time of the policy implementation in the county they live is eligible.

    I need help in generating a variable, which is is the fraction of years that a child from a cohort born in a county are exposed to the policy from conception (i.e., one year before birth) to age 5. So, the faction variable is a function only of the child’s county and year of birth. For example, cohorts who are born one year right after the introduction of the policy in the county they live are considered fully exposed (e.g., =1), while those aged 6 and above in the reform year of each county are defined as non-exposed (e.g., =0).

    Since exposure to the policy depends on the timing of the policy implementation in each country and the year of birth of each child, I would expect that cohorts born from 1991-1996 are not exposed because they are six years old and older relative to the starting point of the policy in 2002. Additionally, some cohorts born in 1998 could be partially exposed (if the timing of the policy implementation in the county they lived was in 2002 - they were 4 years old at that time) or non-exposed (if the timing of the policy implementation in the county they lived was in 2004 - they were 6 years old at that time). Any help is much appreciated. Thanks!

    The data example below where countyID is the county where children reside, yob is the child's year of birth, and enrolled_yr is the timing of the policy implementation in each country.

    Code:
    clear
    input float(countyID yob enrolled_yr)
    161 2004 2002
    161 2004 2002
    161 2006 2002
    161 1991 2002
    161 2001 2002
    161 2001 2002
    161 2001 2002
    161 2006 2002
    161 2002 2002
    161 2002 2002
    161 2002 2002
    161 1994 2002
    161 2006 2002
    167 1997 2002
    167 1997 2003
    167 1997 2003
    167 1997 2003
    167 2004 2003
    162 2004 2003
    162 1999 2003
    162 1999 2003
    162 1999 2003
    162 1999 2003
    162 2003 2003
    162 1993 2003
    162 1993 2003
    162 1995 2004
    162 1995 2004
    162 1995 2004
    162 1995 2004
    163 1995 2004
    163 1991 2004
    163 1993 2004
    163 1993 2004
    163 1998 2004
    163 1998 2004
    163 1998 2004
    163 1998 2004
    163 2004 2004
    163 2004 2004
    163 1995 2004
    163 1995 2004
    163 1995 2004
    163 1992 2006
    163 1992 2006
    164 1992 2006
    164 1992 2006
    164 2001 2006
    164 2001 2006
    164 2001 2006
    164 2004 2006
    164 2004 2006
    164 1991 2006
    164 2003 2006
    164 2003 2006
    164 1991 2006
    164 1992 2006
    164 1992 2005
    164 1991 2005
    165 1994 2005
    165 1994 2005
    165 1993 2005
    165 1998 2005
    165 1998 2005
    165 1998 2005
    165 1998 2005
    165 2001 2005
    165 2001 2005
    165 2002 2005
    165 2002 2005
    165 2002 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 1997 2005
    166 2002 2005
    166 2002 2005
    166 1991 2005
    166 1996 2005
    166 1996 2005
    166 2000 2005
    167 1993 2005
    167 1993 2005
    167 2000 2005
    167 2000 2005
    101 2003 2003
    101 2003 2003
    101 1992 2003
    101 1991 2003
    101 1991 2003
    101 1992 2003
    101 2005 2003
    101 2002 2003
    101 2002 2003
    101 1993 2003
    101 1993 2003
    101 2006 2003
    101 2006 2003
    101 1995 2003
    102 1995 2003
    102 2006 2003
    102 2001 2004
    102 2001 2004
    102 2001 2004
    102 2003 2004
    102 2003 2004
    102 2007 2004
    102 2000 2004
    102 2000 2004
    102 2000 2004
    102 2000 2004
    102 2007 2004
    102 2007 2004
    102 2007 2004
    102 1996 2004
    104 1996 2004
    104 1996 2004
    104 2000 2004
    104 2000 2004
    104 2001 2004
    104 2001 2006
    104 2001 2006
    104 1999 2006
    104 1999 2006
    104 1999 2006
    104 1999 2006
    104 1999 2006
    104 1999 2006
    104 1999 2006
    104 2005 2006
    104 2004 2006
    104 2004 2006
    104 2001 2006
    104 2001 2006
    104 2002 2006
    104 2002 2006
    104 1997 2006
    104 1997 2007
    105 1997 2007
    105 2005 2007
    105 2004 2007
    105 2004 2007
    105 1998 2007
    105 1998 2007
    105 1998 2007
    105 1998 2007
    105 2000 2007
    105 2000 2007
    105 2000 2007
    105 2000 2007
    105 2001 2007
    105 2001 2007
    105 2001 2007
    105 2005 2007
    105 1992 2007
    105 2006 2007
    103 1993 2007
    103 1993 2007
    103 2007 2007
    103 2007 2007
    103 2007 2007
    103 1999 2007
    103 2003 2007
    103 2003 2007
    103 2005 2007
    103 2005 2007
    106 2005 2007
    106 1995 2007
    106 1995 2007
    106 1994 2007
    106 1994 2007
    106 2004 2007
    106 2004 2007
    106 2002 2007
    106 2002 2007
    106 2002 2007
    106 1994 2007
    106 1996 2007
    107 1996 2007
    107 2002 2007
    107 2002 2007
    107 1999 2007
    107 1999 2007
    167 1999 2005
    107 1999 2007
    107 1993 2002
    107 1993 2002
    107 1996 2002
    107 1994 2002
    107 2004 2002
    107 2000 2002
    107 2000 2002
    107 2000 2002
    107 2000 2002
    107 2003 2002
    107 2003 2002
    end

  • #2
    county/country faction/fraction I am going to run with county and fraction.

    Code:
    egen wanted = mean(inrange(yob - enrolled_yr, -1, 5)), by(county)
    If you have missing values, make sure to exclude them.

    Code:
    if !missing(yob, enrolled_yr)

    Comment


    • #3
      Thank you Nick and sorry for the typos.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        county/country faction/fraction I am going to run with county and fraction.

        Code:
        egen wanted = mean(inrange(yob - enrolled_yr, -1, 5)), by(county)
        If you have missing values, make sure to exclude them.

        Code:
        if !missing(yob, enrolled_yr)
        Hi Nick,

        I am sorry for bringing this issue back but it seems there is an issue with the code in 2 because numerous people born between 1991 and 1996 have fraction values. By contrast, I would expect that all these cohorts take on a value of zero because they are at least six years old or older relative to the starting point of the policy in 2002, thus they are not exposed to the policy. Could you please take a look at my original post and code in 2? Many thanks!

        Comment


        • #5
          Perhaps you need yob to be included in the by() option call. If that is not the answer, please give a worked example showing what the answer should be for some concrete cases.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            Perhaps you need yob to be included in the by() option call. If that is not the answer, please give a worked example showing what the answer should be for some concrete cases.
            Thank you for your response, Nick. Including yob into by() does not work since all non-exposed individuals take 0 values (which is correct) but fully exposed and partially exposed cohorts take the same value (=1). I would expect faction values for these cohorts where younger cohorts expose to a greater intensity of the policy than older cohorts within a countryID. An example of some concrete cases below:
            Code:
            clear
            input float(countyID yob enrolled_yr wanted)
            161 1991 2002 0
            161 1992 2002 0
            161 1996 2002 0
            167 1998 2002 0.15
            167 1997 2002 0.14
            162 1997 2005 0
            162 1998 2005 0
            164 2000 2006 0
            164 2002 2006 0.16
            164 2001 2006 0.15
            165 2004 2005 1
            165 2003 2005 0.9
            165 2002 2005 0.8
            end
            As you can see, all cohorts in countyID 161 are equal to 0 since all individuals were 6 years old or older when the policy was implemented. A similar observation can be found in countyID 162. However, despite having the same cohorts as countyID 162, those born in 1997 and 1998 in countyID 167 do not have zero values because the policy was implemented earlier in this countyID compared to countyID 162. A similar logic applies to other countyIDs and cohorts.

            Please use the following data example for future assistance. Thank you.
            Code:
            clear
            input float(countyID yob enrolled_yr)
            161 2004 2002
            161 2004 2002
            161 2006 2002
            161 1991 2002
            161 2001 2002
            161 2001 2002
            161 2001 2002
            161 2006 2002
            161 2002 2002
            161 2002 2002
            161 2002 2002
            161 1994 2002
            161 2006 2002
            167 1997 2003
            167 1997 2003
            167 1997 2003
            167 1997 2003
            167 2004 2003
            162 2004 2003
            162 1999 2003
            162 1999 2003
            162 1999 2003
            162 1999 2003
            162 2003 2003
            162 1993 2003
            162 1993 2003
            162 1995 2003
            162 1995 2003
            162 1995 2003
            162 1995 2003
            163 1995 2004
            163 1991 2004
            163 1993 2004
            163 1993 2004
            163 1998 2004
            163 1998 2004
            163 1998 2004
            163 1998 2004
            163 2004 2004
            163 2004 2004
            163 1995 2004
            163 1995 2004
            163 1995 2004
            163 1992 2004
            163 1992 2004
            164 1992 2006
            164 1992 2006
            164 2001 2006
            164 2001 2006
            164 2001 2006
            164 2004 2006
            164 2004 2006
            164 1991 2006
            164 2003 2006
            164 2003 2006
            164 1991 2006
            164 1992 2006
            164 1992 2006
            164 1991 2006
            165 1994 2005
            165 1994 2005
            165 1993 2005
            165 1998 2005
            165 1998 2005
            165 1998 2005
            165 1998 2005
            165 2001 2005
            165 2001 2005
            165 2002 2005
            165 2002 2005
            165 2002 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 1997 2005
            166 2002 2005
            166 2002 2005
            166 1991 2005
            166 1996 2005
            166 1996 2005
            166 2000 2005
            167 1993 2005
            167 1993 2005
            167 2000 2005
            167 2000 2005
            101 2003 2003
            101 2003 2003
            101 1992 2003
            101 1991 2003
            101 1991 2003
            101 1992 2003
            101 2005 2003
            101 2002 2003
            101 2002 2003
            101 1993 2003
            101 1993 2003
            101 2006 2003
            101 2006 2003
            101 1995 2003
            102 1995 2004
            102 2006 2004
            102 2001 2004
            102 2001 2004
            102 2001 2004
            102 2003 2004
            102 2003 2004
            102 2007 2004
            102 2000 2004
            102 2000 2004
            102 2000 2004
            102 2000 2004
            102 2007 2004
            102 2007 2004
            102 2007 2004
            102 1996 2004
            104 1996 2006
            104 1996 2006
            104 2000 2006
            104 2000 2006
            104 2001 2006
            104 2001 2006
            104 2001 2006
            104 1999 2006
            104 1999 2006
            104 1999 2006
            104 1999 2006
            104 1999 2006
            104 1999 2006
            104 1999 2006
            104 2005 2006
            104 2004 2006
            104 2004 2006
            104 2001 2006
            104 2001 2006
            104 2002 2006
            104 2002 2006
            104 1997 2006
            104 1997 2006
            105 1997 2007
            105 2005 2007
            105 2004 2007
            105 2004 2007
            105 1998 2007
            105 1998 2007
            105 1998 2007
            105 1998 2007
            105 2000 2007
            105 2000 2007
            105 2000 2007
            105 2000 2007
            105 2001 2007
            105 2001 2007
            105 2001 2007
            105 2005 2007
            105 1992 2007
            105 2006 2007
            103 1993 2007
            103 1993 2007
            103 2007 2007
            103 2007 2007
            103 2007 2007
            103 1999 2007
            103 2003 2007
            103 2003 2007
            103 2005 2007
            103 2005 2007
            106 2005 2007
            106 1995 2007
            106 1995 2007
            106 1994 2007
            106 1994 2007
            106 2004 2007
            106 2004 2007
            106 2002 2007
            106 2002 2007
            106 2002 2007
            106 1994 2007
            106 1996 2007
            107 1996 2007
            107 2002 2007
            107 2002 2007
            107 1999 2007
            107 1999 2007
            107 1999 2007
            107 1999 2007
            108 1993 2002
            108 1993 2002
            108 1996 2002
            108 1994 2002
            108 2004 2002
            108 2000 2002
            108 2000 2002
            108 2000 2002
            108 2000 2002
            108 2003 2002
            108 2003 2002
            end
            Last edited by Matthew Williams; 14 Oct 2024, 14:06.

            Comment


            • #7
              Sorry, but I am still lost here.

              Comment


              • #8
                Thank you, Nick. I hope that I have clearly explained what I wanted to obtain in #1 and #6. So, any further help, in addition to Nick, is greatly appreciated.

                Comment

                Working...
                X