I want to make loop code of below.
Code:
gen A01_GLU0_new =. replace A01_GLU0_new = A01_GLU0_ORI replace A01_GLU0_new = A01_GLU0_TR if A01_GLU0_TR !=. gen A01_GLU120_new=. replace A01_GLU120_new = A01_GLU120_ORI replace A01_GLU120_new = A01_GLU120_TR if A01_GLU120_TR !=. gen A01_ALBUMIN_new=. replace A01_ALBUMIN_new = A01_ALBUMIN_ORI replace A01_ALBUMIN_new = A01_ALBUMIN_TR if A01_ALBUMIN_TR !=. gen A01_BUN_new=. replace A01_BUN_new = A01_BUN_ORI replace A01_BUN_new = A01_BUN_TR if A01_BUN_TR !=.
Code:
foreach var of varlist A01_GLU120_ORI A01_ALBUMIN_ORI A01_BUN_ORI {
gen substr(`var',1,length(`var')-3)new=.
replace substr(`var',1,length(`var')-3)new = substr(`var',1,length(`var')-3)ORI
replace substr(`var',1,length(`var')-3)new = substr(`var',1,length(`var')-3_TR if `var'TR !=.
}
0 Response to How can I Make these code to loop code ?
Post a Comment