Hello,
out of my panel dataset I want to choose random observations of id's.
Therefore, I wanted to generate a random number for each id, but some observations are available in 2 waves and others in 3,4,5,6,7 or 8 waves.
The runiform command
gen random = runiform (0, 1)
gives each observation of an id a random number, but I want the id's that are various times inside the panel to have the same random numbers each time.
Here is an example of my data:
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long cid float random int wave
111203 .3488717 2
111203 .2668857 3
111203 .1366463 4
111203 .028556867 6
111203 .8689333 8
111203 .3508549 9
907201 .07110509 8
907201 .32336795 9
907201 .5551032 10
2767201 .875991 3
2767201 .20470947 4
3491201 .8927587 8
3491201 .5844658 9
3491201 .3697791 11
4835201 .8506309 2
4835201 .3913819 4
4835201 .11966132 5
4858201 .7542434 4
4858201 .6950234 5
4858201 .6866152 6
4858201 .9319346 7
4858201 .4548882 8
4858201 .0674011 9
4858201 .3379889 11
6151201 .9748848 6
6151201 .7264384 7
6151201 .04541512 8
6151201 .7459667 9
6151201 .4961259 10
6519201 .7167162 4
6519201 .859742 5
6519201 .13407555 6
6519201 .48844185 7
6519201 .8712187 8
7631201 .7664683 8
7631201 .25125554 9
7631201 .16636477 11
8948201 .7437958 2
8948201 .9805113 3
8948201 .7295772 5
8948201 .9011049 9
9657201 .26436493 5
9657201 .8856509 8
9657202 .882112 10
9657203 .748933 10
10250201 .9196262 8
10250201 .6934533 10
10250201 .2154026 11
10957202 .8285888 2
10957202 .04421536 4
10957202 .8630378 5
11295201 .3526046 4
11295201 .7720399 5
11295201 .5861199 6
11295201 .3227766 7
11295201 .17293066 9
11295201 .8053644 10
11295201 .3060019 11
11295202 .21909967 9
11295202 .724731 10
11295202 .6964867 11
12490201 .9119344 3
12490201 .6795634 4
12490201 .3549416 5
12490201 .73897 6
12490201 .18740167 7
12490201 .3146128 8
12490201 .1375693 9
12490202 .6537739 6
12490202 .27013195 7
12490202 .8998394 8
12490202 .5734232 9
12490202 .11147037 10
12490203 .4145227 9
13345202 .003052204 4
14898201 .6659978 4
14898201 .3462876 6
14902201 .0780235 5
14902201 .12758136 6
14902201 .2297006 7
14902201 .3295547 8
14902201 .4144089 9
14902201 .036084738 10
14902201 .08438109 11
16671201 .009876247 2
16671201 .3200437 3
16671201 .005196966 4
16829201 .22754347 2
16829201 .851468 3
16829201 .9820066 4
16829201 .032479186 6
16829202 .9874847 6
16829202 .894106 7
16829202 .9684734 9
16829202 .23922028 10
17018203 .6927336 2
17018203 .4884359 3
17018203 .4376452 4
17018204 .5858005 6
17018204 .3787092 7
end
out of my panel dataset I want to choose random observations of id's.
Therefore, I wanted to generate a random number for each id, but some observations are available in 2 waves and others in 3,4,5,6,7 or 8 waves.
The runiform command
gen random = runiform (0, 1)
gives each observation of an id a random number, but I want the id's that are various times inside the panel to have the same random numbers each time.
Here is an example of my data:
[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long cid float random int wave
111203 .3488717 2
111203 .2668857 3
111203 .1366463 4
111203 .028556867 6
111203 .8689333 8
111203 .3508549 9
907201 .07110509 8
907201 .32336795 9
907201 .5551032 10
2767201 .875991 3
2767201 .20470947 4
3491201 .8927587 8
3491201 .5844658 9
3491201 .3697791 11
4835201 .8506309 2
4835201 .3913819 4
4835201 .11966132 5
4858201 .7542434 4
4858201 .6950234 5
4858201 .6866152 6
4858201 .9319346 7
4858201 .4548882 8
4858201 .0674011 9
4858201 .3379889 11
6151201 .9748848 6
6151201 .7264384 7
6151201 .04541512 8
6151201 .7459667 9
6151201 .4961259 10
6519201 .7167162 4
6519201 .859742 5
6519201 .13407555 6
6519201 .48844185 7
6519201 .8712187 8
7631201 .7664683 8
7631201 .25125554 9
7631201 .16636477 11
8948201 .7437958 2
8948201 .9805113 3
8948201 .7295772 5
8948201 .9011049 9
9657201 .26436493 5
9657201 .8856509 8
9657202 .882112 10
9657203 .748933 10
10250201 .9196262 8
10250201 .6934533 10
10250201 .2154026 11
10957202 .8285888 2
10957202 .04421536 4
10957202 .8630378 5
11295201 .3526046 4
11295201 .7720399 5
11295201 .5861199 6
11295201 .3227766 7
11295201 .17293066 9
11295201 .8053644 10
11295201 .3060019 11
11295202 .21909967 9
11295202 .724731 10
11295202 .6964867 11
12490201 .9119344 3
12490201 .6795634 4
12490201 .3549416 5
12490201 .73897 6
12490201 .18740167 7
12490201 .3146128 8
12490201 .1375693 9
12490202 .6537739 6
12490202 .27013195 7
12490202 .8998394 8
12490202 .5734232 9
12490202 .11147037 10
12490203 .4145227 9
13345202 .003052204 4
14898201 .6659978 4
14898201 .3462876 6
14902201 .0780235 5
14902201 .12758136 6
14902201 .2297006 7
14902201 .3295547 8
14902201 .4144089 9
14902201 .036084738 10
14902201 .08438109 11
16671201 .009876247 2
16671201 .3200437 3
16671201 .005196966 4
16829201 .22754347 2
16829201 .851468 3
16829201 .9820066 4
16829201 .032479186 6
16829202 .9874847 6
16829202 .894106 7
16829202 .9684734 9
16829202 .23922028 10
17018203 .6927336 2
17018203 .4884359 3
17018203 .4376452 4
17018204 .5858005 6
17018204 .3787092 7
end
Comment