Dear Statalist Users,
I have attached an example of my dataset. Variable plate denotes the city of residence it takes values from 1 to 81. Refpop is my treatment variable. Refpop_1, Refpop_2, .... , Refpop_8 are the forward values of my treatment variables constructed based on origional treatment variable (i.e., Refpop).
I want to create another variable, let's say fake_treatment. For example, if refpop_1 is 0.1 for children residing in city 1 and born in 2013, I want fake_treatment to take value of 0.1 for all children born in 2003 and reside in city 1. Or, if refpop_1 is 0.2 for children residing in city 2 and born in 2014, I want this fake_treatment to take value of 0.2 for all children born in 2004 and reside in city 2. It goes like that. Precesily, I want 2013 refpop_1 values to be replaced with children born in 2003, 2014 refpop_1 values to be replaced with children born in 2004, 2015 refpop_1 values to be replaced with children born in 2005, 2016 refpop_1 values to be replaced with children born in 2006, 2017 refpop_1 values to be replaced with children born in 2007, and 2018 refpop_1 values to be replaced with children born in 2008 conditional on their city of residence.
Indeed, there are 81 cities in my dataset (denoted by plate) and I try to create a fake treatment variable based on the forward values of my actual treatment variable. Since there are 81 cities, I could not figure out the exact code. Thank you in advance.
I have attached an example of my dataset. Variable plate denotes the city of residence it takes values from 1 to 81. Refpop is my treatment variable. Refpop_1, Refpop_2, .... , Refpop_8 are the forward values of my treatment variables constructed based on origional treatment variable (i.e., Refpop).
I want to create another variable, let's say fake_treatment. For example, if refpop_1 is 0.1 for children residing in city 1 and born in 2013, I want fake_treatment to take value of 0.1 for all children born in 2003 and reside in city 1. Or, if refpop_1 is 0.2 for children residing in city 2 and born in 2014, I want this fake_treatment to take value of 0.2 for all children born in 2004 and reside in city 2. It goes like that. Precesily, I want 2013 refpop_1 values to be replaced with children born in 2003, 2014 refpop_1 values to be replaced with children born in 2004, 2015 refpop_1 values to be replaced with children born in 2005, 2016 refpop_1 values to be replaced with children born in 2006, 2017 refpop_1 values to be replaced with children born in 2007, and 2018 refpop_1 values to be replaced with children born in 2008 conditional on their city of residence.
Indeed, there are 81 cities in my dataset (denoted by plate) and I try to create a fake treatment variable based on the forward values of my actual treatment variable. Since there are 81 cities, I could not figure out the exact code. Thank you in advance.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float child_birth_year double refpop float plate double(refpop_1 refpop_2 refpop_3 refpop_4 refpop_5 refpop_6 refpop_7) 2003 0 1 . . . . . . . 2004 0 1 0 . . . . . . 2005 0 1 0 0 . . . . . 2006 0 1 0 0 0 . . . . 2007 0 1 0 0 0 0 . . . 2008 0 1 0 0 0 0 0 . . 2009 0 1 0 0 0 0 0 0 . 2010 0 1 0 0 0 0 0 0 0 2011 0 1 0 0 0 0 0 0 0 2012 . 1 0 0 0 0 0 0 0 2013 .009273339807454824 1 . 0 0 0 0 0 0 2014 .02936181946792312 1 .009273339807454824 . 0 0 0 0 0 2015 .0655555155918426 1 .02936181946792312 .009273339807454824 . 0 0 0 0 2016 .0718090373940462 1 .0655555155918426 .02936181946792312 .009273339807454824 . 0 0 0 2017 .07464182522269777 1 .0718090373940462 .0655555155918426 .02936181946792312 .009273339807454824 . 0 0 2018 .09233631862269061 1 .07464182522269777 .0718090373940462 .0655555155918426 .02936181946792312 .009273339807454824 . 0 2004 0 2 . . . . . . . 2005 0 2 0 . . . . . . 2006 0 2 0 0 . . . . . 2007 0 2 0 0 0 . . . . 2008 0 2 0 0 0 0 . . . 2009 0 2 0 0 0 0 0 . . 2010 0 2 0 0 0 0 0 0 . 2011 0 2 0 0 0 0 0 0 0 2012 . 2 0 0 0 0 0 0 0 2013 .01724893600819041 2 . 0 0 0 0 0 0 2014 .056442755971468944 2 .01724893600819041 . 0 0 0 0 0 2015 .037366207789350785 2 .056442755971468944 .01724893600819041 . 0 0 0 0 2016 .04196231396008021 2 .037366207789350785 .056442755971468944 .01724893600819041 . 0 0 0 2017 .04458019917588229 2 .04196231396008021 .037366207789350785 .056442755971468944 .01724893600819041 . 0 0 2018 .04995811722101417 2 .04458019917588229 .04196231396008021 .037366207789350785 .056442755971468944 .01724893600819041 . 0 2004 0 3 . . . . . . . 2005 0 3 0 . . . . . . 2006 0 3 0 0 . . . . . 2007 0 3 0 0 0 . . . . 2008 0 3 0 0 0 0 . . . 2009 0 3 0 0 0 0 0 . . 2010 0 3 0 0 0 0 0 0 . 2011 0 3 0 0 0 0 0 0 0 2012 . 3 0 0 0 0 0 0 0 2013 0 3 . 0 0 0 0 0 0 2014 .0007167852468393355 3 0 . 0 0 0 0 0 2015 . 3 .0007167852468393355 0 . 0 0 0 0 2016 .0059937582340705235 3 . .0007167852468393355 0 . 0 0 0 2017 . 3 .0059937582340705235 . .0007167852468393355 0 . 0 0 2018 . 3 . .0059937582340705235 . .0007167852468393355 0 . 0 2003 0 4 . . . . . . . 2004 0 4 0 . . . . . . 2005 0 4 0 0 . . . . . 2006 0 4 0 0 0 . . . . 2007 0 4 0 0 0 0 . . . 2008 0 4 0 0 0 0 0 . . 2009 0 4 0 0 0 0 0 0 . 2010 0 4 0 0 0 0 0 0 0 2011 0 4 0 0 0 0 0 0 0 2012 . 4 0 0 0 0 0 0 0 2013 0 4 . 0 0 0 0 0 0 2014 .00018449435631764024 4 0 . 0 0 0 0 0 2015 .0014685750762884163 4 .00018449435631764024 0 . 0 0 0 0 2016 .0015811166336421772 4 .0014685750762884163 .00018449435631764024 0 . 0 0 0 2017 .0018597031116818136 4 .0015811166336421772 .0014685750762884163 .00018449435631764024 0 . 0 0 2018 .0020958558877683937 4 .0018597031116818136 .0015811166336421772 .0014685750762884163 .00018449435631764024 0 . 0 2003 0 5 . . . . . . . 2004 0 5 0 . . . . . . 2005 0 5 0 0 . . . . . 2006 0 5 0 0 0 . . . . 2007 0 5 0 0 0 0 . . . 2008 0 5 0 0 0 0 0 . . 2009 . 5 0 0 0 0 0 0 . 2010 . 5 0 0 0 0 0 0 0 2011 0 5 . . 0 0 0 0 0 2012 . 5 0 . . 0 0 0 0 2013 0 5 . 0 . . 0 0 0 2014 .0002986982729265859 5 0 . 0 . . 0 0 2015 . 5 .0002986982729265859 0 . 0 . . 0 2016 . 5 0 .0002986982729265859 0 . 0 . . 2017 .0012007670571648754 5 . . .0002986982729265859 0 . 0 . 2018 . 5 .0012007670571648754 . . .0002986982729265859 0 . 0 2003 0 6 . . . . . . . 2004 0 6 0 . . . . . . 2005 0 6 0 0 . . . . . 2006 0 6 0 0 0 . . . . 2007 0 6 0 0 0 0 . . . 2008 0 6 0 0 0 0 0 . . 2009 0 6 0 0 0 0 0 0 . 2010 0 6 0 0 0 0 0 0 0 2011 0 6 0 0 0 0 0 0 0 2012 . 6 0 0 0 0 0 0 0 2013 0 6 . 0 0 0 0 0 0 2014 .006287046421035958 6 0 . 0 0 0 0 0 2015 .011310815647871755 6 .006287046421035958 0 . 0 0 0 0 2016 .014070619458492507 6 .011310815647871755 .006287046421035958 0 . 0 0 0 2017 .016816801335201005 6 .014070619458492507 .011310815647871755 .006287046421035958 0 . 0 0 2018 .020153965575486883 6 .016816801335201005 .014070619458492507 .011310815647871755 .006287046421035958 0 . 0 2003 0 7 . . . . . . . 2004 0 7 0 . . . . . . 2005 0 7 0 0 . . . . . 2006 0 7 0 0 0 . . . . 2007 0 7 0 0 0 0 . . . 2008 0 7 0 0 0 0 0 . . end

Comment