Hello Statalist.

I have a dataset that looks like this:
pid value number
1 0.12 2
1 0.4 2
1 0.3 2
1 0.01 2
2 0.2 3
2 0.321 3
2 0.15 3
2 0.4 3
What I want to do is the following: In the case of the respondent 1 (pid=1) I want stata to create a dummy variable turning 1 in the two (number) lowest values for that respondent.

In the case of the respondent 2 (id=2) I want Stata to create a dummy variable turning 1 in the three lowest values. So the result would be the following:
pid value number newvar
1 0.12 2 1
1 0.4 2 0
1 0.3 2 0
1 0.01 2 1
2 0.2 3 1
2 0.321 3 1
2 0.15 3 1
2 0.4 3 0
Thank you very much in advance!!