Hello, Statalist community
Your help helps me a lot to walk and evolve in Stata. I have a situation here where I can't completely solve the case.
In my database, I have children (id) with 2 or more anthropometric measurements. For my model (I intend to use linear regression of mixed effects), these anthropometric measurements must have a minimum interval of 1 month between measurements. For this, I created the following variables:
*inter_caen: data interval for recording food consumption (exposure) and nutritional status (waste)
*within the same id: subtrai or value of each line for the first line
bysort id: gen inter_EN = inter_caen - inter_caen[1]
*within the same id: subtrai or value of each line from the previous line
bysort id: gen inter_EN1 = inter_caen - inter_caen[_n-1]
Starting from this, I created a variable to choose the records that fit the mine condition: guarantee that the anthropometry records selected have a minimum interval of one month (30 days) between them. I used this code:
bysort id : gen inter_valid1 = cond(inter_EN > 30 | mod(inter_EN, 30) == 0, inter_EN, .) & inter_EN1>=30
This code is true for almost everything, but there are cases like or with id 77631138 that is not true. Note that the second record is 28 days relative to the first and the third is 34 days relative to the first record. Both mark 0 for the variable generated "inter_valid", more than the third record should be valid because it meets the condition of a minimum of 30 days in relation to the first record. How could I solve this question?
I thank the help of all you
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
Your help helps me a lot to walk and evolve in Stata. I have a situation here where I can't completely solve the case.
In my database, I have children (id) with 2 or more anthropometric measurements. For my model (I intend to use linear regression of mixed effects), these anthropometric measurements must have a minimum interval of 1 month between measurements. For this, I created the following variables:
*inter_caen: data interval for recording food consumption (exposure) and nutritional status (waste)
*within the same id: subtrai or value of each line for the first line
bysort id: gen inter_EN = inter_caen - inter_caen[1]
*within the same id: subtrai or value of each line from the previous line
bysort id: gen inter_EN1 = inter_caen - inter_caen[_n-1]
Starting from this, I created a variable to choose the records that fit the mine condition: guarantee that the anthropometry records selected have a minimum interval of one month (30 days) between them. I used this code:
bysort id : gen inter_valid1 = cond(inter_EN > 30 | mod(inter_EN, 30) == 0, inter_EN, .) & inter_EN1>=30
This code is true for almost everything, but there are cases like or with id 77631138 that is not true. Note that the second record is 28 days relative to the first and the third is 34 days relative to the first record. Both mark 0 for the variable generated "inter_valid", more than the third record should be valid because it meets the condition of a minimum of 30 days in relation to the first record. How could I solve this question?
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 float(idade_meses_en cenario peso alt inter_caen seq_EN1 max_EN1 inter_EN inter_EN1) 77631138 1.6427104 0 4.57 56 -34 1 4 0 . 77631138 2.562628 0 5.56 58 -6 2 4 28 28 77631138 2.759754 0 5.56 58 0 3 4 34 6 77631138 11.301848 0 87.98 71 260 4 4 294 260 77632633 .9856262 1 3.75 50 -31 1 4 0 . 77632633 2.0041068 1 4.76 53 0 2 4 31 31 77632633 3.0554416 1 5.49 57 32 3 4 63 32 77632633 5.223819 1 6.56 61 98 4 4 129 66 77647867 1.905544 1 6.3 60 0 1 4 0 . 77647867 2.9240246 1 7.6 63 31 2 4 31 31 77647867 3.449692 1 8 64 47 3 4 47 16 77647867 10.349076 1 11.6 73 257 4 4 257 210 77648623 1.8398356 0 5.38 57 0 1 4 0 . 77648623 2.858316 0 5.95 58 31 2 4 31 31 77648623 5.026694 0 6.8 64 97 3 4 97 66 77648623 5.946612 0 6.7 65 125 4 4 125 28 end label values cenario cenario label def cenario 0 "LM exclusivo", modify label def cenario 1 "Substitutos do leite materno", modify
Comment