Dear Statalist I am trying to construct a loop that would help me extracting the data I need from an extremely large database.
Precisely I am trying to extract a specific sub-list of codes from a much larger list. I have the list I need in Excel and it doesn't have any mathematical order. I will try to be more specific using an example:
File in excel:
CODES
1111
1214
1317
2324
etc
I can easily make the list going through a single row rather than the column (111 1213 1317 2324, etc)
Because we are talking about a list of almost 1000 codes I was trying to write a loop with forvalues using the copy and past function from excel but because the numbers do not follow a specific interval I am not sure how to construct it.
Obviously if I write something like:
forvalue x = 111 1214 1317 2324 etc {
generate newvar = .
replace newvar = 1 if code ==`x'
}
drop if newvar!=1
Stata won't run it as the forvalue is not correctly specified but my question is whether there is a way to construct the loop in a way that I might simply replace the list of values with a simple copy and past to make it work, even if the numbers do not follow any specific rationale.
Thanks
Precisely I am trying to extract a specific sub-list of codes from a much larger list. I have the list I need in Excel and it doesn't have any mathematical order. I will try to be more specific using an example:
File in excel:
CODES
1111
1214
1317
2324
etc
I can easily make the list going through a single row rather than the column (111 1213 1317 2324, etc)
Because we are talking about a list of almost 1000 codes I was trying to write a loop with forvalues using the copy and past function from excel but because the numbers do not follow a specific interval I am not sure how to construct it.
Obviously if I write something like:
forvalue x = 111 1214 1317 2324 etc {
generate newvar = .
replace newvar = 1 if code ==`x'
}
drop if newvar!=1
Stata won't run it as the forvalue is not correctly specified but my question is whether there is a way to construct the loop in a way that I might simply replace the list of values with a simple copy and past to make it work, even if the numbers do not follow any specific rationale.
Thanks
Comment