Hi guys. Any help will be appreciated. I don't know any program language and I need something that I believe I cannot resolve otherwise
The pertinent variables look like this:
modedel id_sn
2 61
1 61
3 61
3 61
1 61
2 68
3 68
3 68
4 68
1 68
1 59
1 59
1 59
4 59
2 61
2 61
3 61
4 61
2 61
....
I need to assign a serial running number to a new variable (new_var) that will run from 1,2,3....it should change every time that the value in "id_sn" changes.
The problem is that "id_sn" can repeat itself many times in the database so I figure that the dataset must remain sorted. I need it later to calculate the proportion of certain value (e.g. "2") in "modedel" for each "new_var" (probably by using 'collapse')
The output should be:
modedel id_sn new_var
2 61 1
1 61 1
3 61 1
3 61 1
1 61 1
2 68 2
3 68 2
3 68 2
4 68 2
1 68 2
1 59 3
1 59 3
1 59 3
4 59 3
2 61 4
2 61 4
3 61 4
4 61 4
2 61 4
Thank you!
The pertinent variables look like this:
modedel id_sn
2 61
1 61
3 61
3 61
1 61
2 68
3 68
3 68
4 68
1 68
1 59
1 59
1 59
4 59
2 61
2 61
3 61
4 61
2 61
....
I need to assign a serial running number to a new variable (new_var) that will run from 1,2,3....it should change every time that the value in "id_sn" changes.
The problem is that "id_sn" can repeat itself many times in the database so I figure that the dataset must remain sorted. I need it later to calculate the proportion of certain value (e.g. "2") in "modedel" for each "new_var" (probably by using 'collapse')
The output should be:
modedel id_sn new_var
2 61 1
1 61 1
3 61 1
3 61 1
1 61 1
2 68 2
3 68 2
3 68 2
4 68 2
1 68 2
1 59 3
1 59 3
1 59 3
4 59 3
2 61 4
2 61 4
3 61 4
4 61 4
2 61 4
Thank you!
Comment