Hi, guys
I have a database where the same id can have several food consumption records (ranging from 1 to 16 records per id in the complete database). In the example below, each id has 4 records. I need to choose only 1 record and I chose to choose the last record (seq_ca6m==max_ca6m). However, note that for id 11302767, the last record is missing, as this record does not fit into any category of the scenario variable. In this case, I would like to choose the record immediately closest to the last position that is not missing. How can I do this, systematically?
Additional information: I have the following decision tree for choosing the food intake record:
1) Selection of id with 1 food consumption record; 2) In case of id with multiple records: choose the last record. If this record is missing for the scenario variable, immediately choose the record closest to the last one that is not missing
I thank the help of all you
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
I have a database where the same id can have several food consumption records (ranging from 1 to 16 records per id in the complete database). In the example below, each id has 4 records. I need to choose only 1 record and I chose to choose the last record (seq_ca6m==max_ca6m). However, note that for id 11302767, the last record is missing, as this record does not fit into any category of the scenario variable. In this case, I would like to choose the record immediately closest to the last position that is not missing. How can I do this, systematically?
Additional information: I have the following decision tree for choosing the food intake record:
1) Selection of id with 1 food consumption record; 2) In case of id with multiple records: choose the last record. If this record is missing for the scenario variable, immediately choose the record closest to the last one that is not missing
I thank the help of all you
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id byte sexo_ca int ano_acomp_ca float(datanasc_ca dataacomp_ca idade_meses_ca seq_ca6m max_ca6m cenario) 210714 0 2017 20874 20950 2.49692 1 4 1 210714 0 2017 20874 20996 4.0082135 2 4 1 210714 0 2017 20874 21020 4.796715 3 4 2 210714 0 2017 20874 21049 5.749487 4 4 1 11302767 0 2018 21144 21243 3.252567 1 4 0 11302767 0 2018 21144 21271 4.172485 2 4 0 11302767 0 2018 21144 21297 5.026694 3 4 0 11302767 0 2018 21144 21325 5.946612 4 4 . 29640336 1 2016 20661 20730 2.2669406 1 4 2 29640336 1 2016 20661 20768 3.5154004 2 4 0 29640336 1 2016 20661 20794 4.36961 3 4 1 29640336 1 2017 20661 20824 5.355236 4 4 2 39151761 0 2017 21167 21174 .22997946 1 4 0 39151761 0 2018 21167 21215 1.577002 2 4 2 39151761 0 2018 21167 21242 2.4640656 3 4 2 39151761 0 2018 21167 21271 3.416838 4 4 2 end format %td datanasc_ca format %td dataacomp_ca label values sexo_ca sexo label def sexo 0 "feminino", modify label def sexo 1 "masculino", modify label values cenario cenario label def cenario 0 "LM exclusivo", modify label def cenario 1 "introducao de outros liquidos", modify label def cenario 2 "IA precoce", modify
Comment