here is my question: I have two databases. One of them ( BASE1 ) has some Mexican states and their respective municipalities ( 19,138 vol. ) For 2008-2009:
1. **State Municipality Year ID**
2. Aguascalientes Calvillo 2008 _
3. Aguascalientes Calvillo 2009 _
4. Baja California Tecate 2008 _
5. Baja California Tecate 2009 _
6. (...)
Another database ( BASE2 ) contains an identifier for all municipalities ( 2,457 vol. ):
1. **State Municipality ID**
2. Aguascalientes Calvillo 1001
3. Baja California Tecate 2003
4. (...)
I want to assign an appropriate identifier (BASE2) for each case in BASE1.
I am creating the following code:
for (i in 1:2457){
for (j in 1:19138) {
if (BASE_2$MUNICIPALITY_NAME[i]==BASE1$MUNICIPALITY_NAME[j] && BASE2$STATE_NAME[i]==BASE1$STATE_NAME[j]) {
BASE1$MUNICIPALITY_ID[j]=BASE2$MUNICIPALITY_ID[i]
}
}
}
The reason I am creating the code as follows:
if (BASE_2$MUNICIPALITY_NAME[i]==BASE1$MUNICIPALITY_NAME[j] **&& BASE2$STATE_NAME[i]==BASE1$STATE_NAME[j]**)
consists in the fact that in some states there are similarly named municipalities.
The code works (I tested it with a subset of the databases), but it takes too much time to execute it. The question is:
? , , 2 457 19,138 = 47,022,066 ( )