Hi all,
I have been trying to look at different forums, and found similar answers, but I have a certain application I cannot find an answer to.
I have sorted my data by a group variable and want to keep a particular group if an indicator variable denoted indicatorvar ==1 at least once in the group variable. However, I get two different sized datasets when doing the following two different methods, holding other code equal:
bysort group: keep if indicatorvar[_N]
bysort (indicatorvar): keep if indicatorvar[_N]
Upon browsing both results, it seems as if it keeps the entire group as long as the indicator variable is activated in at least one observation within a group. However, the first result is much smaller observation-wise than the second result.
I cannot understand why it is doing it. Any help would be appreciated.
Similar forum is here:-by- syntax of adding another variable in brackets - Statalist
I have been trying to look at different forums, and found similar answers, but I have a certain application I cannot find an answer to.
I have sorted my data by a group variable and want to keep a particular group if an indicator variable denoted indicatorvar ==1 at least once in the group variable. However, I get two different sized datasets when doing the following two different methods, holding other code equal:
bysort group: keep if indicatorvar[_N]
bysort (indicatorvar): keep if indicatorvar[_N]
Upon browsing both results, it seems as if it keeps the entire group as long as the indicator variable is activated in at least one observation within a group. However, the first result is much smaller observation-wise than the second result.
I cannot understand why it is doing it. Any help would be appreciated.
Similar forum is here:-by- syntax of adding another variable in brackets - Statalist

Comment