Hi all,
Have a fabulous weekend,
I have a conditional code below
The idea is that: my dataset for these countries is from 1989 to 2020 (yr from 1989 to 2020). But I just want to keep the sample from 1990 to 2020
Afterward, I want to create a variable called pt. The pt variable receive the value of 0 if geogn="UNITEDS" and the year is from 1990 to 1992 (one year before 1993) and receiving the value of 1 if geogn="UNITEDS" and the year is from 1993 to 2020. Similarly, the pt variable receiving the value of 1 if geogn=" SOUTHKOREA " and the year is from 1997 to 2020 and receive the value of 0 from 1990 to 1996(one year before 1997).
A similar creation for other countries, where 1993, 1997, 2000,2001, 2004, 2018 are law implementation years of the countries.
My novice code is as below
data gen_post_treat;
set matching;
yr=input(year, ?? 32.);/*year is a character variable, so I convert to numeric variable*/
if geogn="UNITEDS" & yr in (1993:2020)
| geogn="SOUTHKOREA" & yr in (1997:2020)
| geogn="BRAZIL" & yr in (2000:2020)
| geogn="CANADA" & yr in (2000:2020)
| geogn="CZECH" & yr in (2001:2020)
| geogn="LATVIA" & yr in (2004:2020)
| geogn="VIETNAM" & yr in (2018:2020)
then pt=1;
else if yr ne 1989 then pt=0;
run;
And last but not least, I want to create a variable called the converted year (named cvt_yr) that focuses on 9 years surrounding the law implementation years.
For example, in SOUTHKOREA case:
cvt_yr= -4 if geogn="SOUTHKOREA" & yr=1993
cvt_yr= -3 if geogn="SOUTHKOREA" & yr=1994
cvt_yr= -2 if geogn="SOUTHKOREA" & yr=1995
cvt_yr= -1 if geogn="SOUTHKOREA" & yr=1996
cvt_yr= 0 if geogn="SOUTHKOREA" & yr=1997
cvt_yr= 1 if geogn="SOUTHKOREA" & yr=1998
....
cvt_yr= 5 if geogn="SOUTHKOREA" & yr=2002
Similarly
cvt_yr= -4 if geogn="CZECH" & yr=1997 ... cvt_yr= 0 if geogn="CZECH" & yr=2001 ... cvt_yr= 5 if geogn="CZECH" & yr=2006
Similarly applied for other countries.
For UNITEDS , we only trace back to 1990 due to data limitation
cvt_yr= -3 if geogn="UNITEDS" & yr=1990
and for Vietnam, we only trace forward to 2020 due to data limitation
cvt_yr= 2 if geogn="VIETNAM" & yr=2020
Please let me know if my explanation is not clear.
Thank you so much and warm regards.
Phil.
... View more