Hello,
I am in the process of making documents for data reconciliation. All the data should have been double entered, but I have about 30 ids that were only entered once.
This is going to sound like a weird request, but it’s part of the data cleaning process. How can I create additional observations for the data that was only entered once? I have a variable called dup that counts the number of times the id variable was entered into the dataset.
Example Data in Current Form
I would like to create an additional observation for each id that was entered once. In the new observation row, I would like only the id variable to have a value (the rest can be missing)
What I want the data to look like
I was working on quite a few loops but got pretty stuck. I settled on the one below but I am not quite sure how to replace in the next subsequent observation row. Any advice would be greatly appreciated.
foreach x in 12 13 18 {
set obs `=_N+1'
replace id = `x' in 8
}
I am in the process of making documents for data reconciliation. All the data should have been double entered, but I have about 30 ids that were only entered once.
This is going to sound like a weird request, but it’s part of the data cleaning process. How can I create additional observations for the data that was only entered once? I have a variable called dup that counts the number of times the id variable was entered into the dataset.
Example Data in Current Form
obs | id | dup | gender |
1 | 12 | 1 | 2 |
2 | 13 | 1 | 2 |
3 | 14 | 2 | 1 |
4 | 15 | 2 | 1 |
5 | 16 | 2 | 3 |
6 | 17 | 2 | 2 |
7 | 18 | 1 | 1 |
What I want the data to look like
obs | id | dup | gender |
1 | 12 | 1 | 2 |
2 | 13 | 1 | 2 |
3 | 14 | 2 | 1 |
4 | 15 | 2 | 1 |
5 | 16 | 2 | 3 |
6 | 17 | 2 | 2 |
7 | 18 | 1 | 1 |
8 | 12 | . | . |
9 | 13 | . | . |
10 | 18 | . | . |
foreach x in 12 13 18 {
set obs `=_N+1'
replace id = `x' in 8
}
Comment