I am using Stata version 17 with Windows 10 and I have been looking at the pdf documentation for the stset command, specifically the "if() versus if exp" example on pages 469-470. There are two stset commands in this section and I would expect both commands to "stset" 2 of the three records (i.e. _st == 1 for records where x1!=22. Based on the documentation, for the first command, I expect _t0 = 0 and 7 and _t = 7 and 11 for the two records, respectively, while for the second command, I expect _t0 = 0 and 9 and _t = 7 and 11 for the two records, respectively.
The code below produces the simple three line dataset used in the example and runs the two stset commands. Both commands produce the same result and neither is what I expected based on the text of the example. I tried adding "id(patno)" as an option to both commands to account for the fact that these records are from a single subject, but that result was not what I expected either (only the first record was "stset", i.e. _st == 1).
What commands would be necessary to produce the results described in the example, especially the "correct" result that is supposed to come from the second stset command?
The code below produces the simple three line dataset used in the example and runs the two stset commands. Both commands produce the same result and neither is what I expected based on the text of the example. I tried adding "id(patno)" as an option to both commands to account for the fact that these records are from a single subject, but that result was not what I expected either (only the first record was "stset", i.e. _st == 1).
What commands would be necessary to produce the results described in the example, especially the "correct" result that is supposed to come from the second stset command?
Code:
clear set obs 3 foreach var in patno t x1 x2 code { gen `var' = . } replace patno = 3 replace t = 7 in 1 replace t = 9 in 2 replace t = 11 in 3 replace x1 = 20 in 1 replace x1 = 22 in 2 replace x1 = 21 in 3 replace x2 = 5 replace code = 14 in 1 replace code = 23 in 2 replace code = 29 in 3 list stset t if x1!=22, failure(code==14) list stset t, if(x1!=22) failure(code==14) list
Comment