Hi all,

I have some data of Blood pressure in pediatric data, my task is recode Blood pressure in:

1=Hipotension (below range)
2=Normal (range in data table)
3=Hypertension (up range)

To do this I have a table with multples "if" to make the recodification because range depending of sex and age in my example. I attach the table but also you can see the link: https://medicine.uiowa.edu/iowaproto...-normal-ranges.

I do the recodification in a normal way (no loop), but I wonder if its possible make this with a loop (I tried but I failed...). Maybe some clue to I complete the loop code...
Example

Code:
clear all
set more off
webuse nhanes2

* dataset example its not for pediatric data, so I make some modifications:

gen age2=age-20
drop if age2 >13
sum age2

Code:
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        age2 |      3055    5.986579    3.972171          0         13
tab sex

Code:
    1=male, |
   2=female |      Freq.     Percent        Cum.
------------+-----------------------------------
       Male |      1,469       48.09       48.09
     Female |      1,586       51.91      100.00
------------+-----------------------------------
      Total |      3,055      100.00
* diastolic pressure recodification

gen diastpr_recode=bpdiast

// diastolic pressure recodification
//            girls

// 0 AGE
recode diastpr_recode   ///
(min/36=1 ) ///
(37/56=2 )  ///
(57/max=3) ///
if sex==2 & age2==0  

// 1 AÑO
recode diastpr_recode   ///
(min/41=1 ) ///
(42/58=2  )  ///
(59/max=3) ///
if sex==2 & age2==1

// 2 AÑO
recode diastpr_recode   ///
(min/47=1 ) ///
(48/62=2 )  ///
(63/max=3) ///
if sex==2 & age2==2

// 3 AÑO
recode diastpr_recode  ///
(min/49=1 ) ///
(50/65=2  )  ///
(66/max=3) ///
if sex==2 & age2==3

***... I completed all years until girls 13 years old

// diastolic pressure:
//       boys
//////////////////////

// 0 AGE
recode diastpr_recode   ///
(min/55=1 ) ///
(37/56=2 )  ///
(57/max=3) ///
if sex==1 & age2==0

// 1 AÑO
recode diastpr_recode   ///
(min/40=1 ) ///
(41/54=2 )  ///
(55/max=3) ///
if sex==1 & age2==1

// 2 AÑOS
recode diastpr_recode   ///
(min/43=1 ) ///
(44/58=2 ) ///  ///
(59/max=3) ///
if sex==1 &  age2==2

// 3 AÑOS
recode diastpr_recode   ///
(min/46=1 ) ///
(47/61=2  )  ///
(62/max=3) ///
if sex==1 & age2==3

***... I completed all years until boys 13 years old

label define diastpr_recode 1 "Hipotension" 2 "Normal" 3 "Hypertension"

label value diastpr_recode diastpr_recode
Array