Hello Everyone,
I am trying to create a variable ,"grad_AA", that will determine respondents' graduation year using the variable D_AA, which records respondents' graduation dates in month. The value of this variable is between 235 and 456 months. The year of graduation is determine using a interval. For example when D_AA is between [235; 240] the correspondent graduation year is 1999.
I have tried this following loop but it is giving me errors.
Can anyone help me figure out what is wrong?
foreach i of D_AA 235/456{
gen grad_AA `i'=1999 if `i'>=235 & <=240
replace grad_AA `i' = 2000 if `x' >=241 & <=252
replace grad_AA`i'=2001 if `i' >=253 & G4<=264
replace grad_AA`i'=2002 if `i' >=264 & <=276
replace grad_AA`i' =2003 if `i' >=277 & <=288
replace grad_AA`i' =2004 if `i' >=289 & <=300
replace grad_AA`i'=2005 if `i' >=301 & <=312
replace grad_AA`i' =2006 if `i' >=313 & <=324
replace grad_AA`i'=2007 if `i' >=325 & <=336
replace grad_AA`i' =2008 if `i' >=337 & <=348
replace grad_AA`i' = 2009 if `i' >=349 & <=360
replace grad_AA`i' =2010 if `i' >=361 & <=372
replace grad_AA `i' =2011 if `i' >=372 & <=384
replace grad_AA`i' =2012 if `i' >=385 & <=396
replace grad_AA`i' =2013 if `i' >=397 & <=408
replace grad_AA`i' =2014 if `i' >=409 & <=420
replace grad_AA`i' =2015 if `i' >=421 & <=432
replace grad_AA `i' =2016 if `i' >=433 & <=444
replace grad_AA`i' =2017 if `i' >=445 & <=456)
replace grad_AA`i' =2018 if `i' >=457 & <=468)
replace Grad_AA `i'=. if `i'=.
}
Thank you so much for your help.
Related Posts with Creating a variable with several condition using the foreach loop
filling blank spaces for data in long formatMy data are repeated measures in long format as shown below. Since this is the same participant, How…
convert a matrix to a column vector, and then output it to Excel fileHello, I need your help on matrix and Excel in Stata. I have a matrix m and would like to stack its …
Extract year from DateHallo, I have have a little problem and would be thankful if anyone could help me. My dataset conta…
Getting the value of kernel density function estimate at specific coordinateDear all, I estimate the kernel density of variable var1 and at the mean of var1 I would like to dr…
Xblc package (splines)Hi all clever people! I would like to make a smooth spline graph using the xblc package (for cox re…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a variable with several condition using the foreach loop
Post a Comment