Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73322

foreach with strange error

$
0
0
Would anyone know why the `i' does not show up in the \`i'\ part of my code? Stata is having trouble finding the file because it does not read the link correctly in the foreach below

Code:
. foreach k in 00 10 {
  2. 
. clear
  3. tempfile temp
  4. save `temp', emptyok
  5. 
. foreach i in AC AM AP AL CE DF ES GO MA MS MT PA PB PE PI PR RN RO RR SC SE TO RS RJ MG BA SP1 SP2 {
  6. clear
  7. if `k'==00 {
  8. import excel using "C:\Users\Paula\Documents\Pesquisa\DADOS\IBGE\Censos\agregado_setor\20`k'\dados_brutos\`i'\Basico_`i'.
> xls", firstrow
  9. }
 10. if `k'==10 {
 11. import excel using "C:\Users\Paula\Documents\Pesquisa\DADOS\IBGE\Censos\agregado_setor\20`k'\dados_brutos\`i'\EXCEL\Basic
> o_`i'.xlsx", firstrow
 12. }
 13. rename Cod_setor C`k'setor
 14. keep C`k'setor
 15. destring C`k'setor, replace
 16. format C`k'setor %15.0f
 17. append using `temp'
 18. save `"`temp'"', replace
 19. }
 20. save setores`k'_temp.dta, replace
 21. }
(note: dataset contains 0 observations)
file C:\Users\Paula\AppData\Local\Temp\ST_03000001.tmp saved
file C:\Users\Paula\Documents\Pesquisa\DADOS\IBGE\Censos\agregado_setor\2000\dados_brutos\Basico_AC.xls not found
r(601);

end of do-file

r(601);

Viewing all articles
Browse latest Browse all 73322

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>