Coder Social home page Coder Social logo

importinegi's Introduction

Introduccion

importinegi es un paquete de R para descargar y gestionar bases de datos abiertas del INEGI. El paquete facilita la búsqueda, descarga y gestión de los datos abiertos del INEGI. Con la version 1.2.1 del paquete se pueden descargar y gestionar los datos de los siguientes proyectos estadisticos:

  • Censo (y Conteo) Poblacion y Vivienda (1990-2010)
  • Censo Nacional de Gobiernos Municipales y Delegacionales (2011-2017)
  • Encuesta Nacional de Ingreso y Gasto (ENIGH) (2008-2014)
  • Encuesta Nacional de Ocupación y Empleo (ENOE) (2005-2018)
  • Red Nacional Carretera (2014-2016)
  • Marco Geoestadistico Nacional (1995-2018)

Instalacion

Última versión estable 1.2.1 (desde CRAN):

install.packages("importinegi")
library(importinegi)
  • Nota de la versión 1.2.1. Se actualizó la nueva URL del Repositorio Nacional de Metadatos. Se reemplazo el paquete rgdal por sf.
  • Nota de la versión 1.2.0. Se arreglan problemas con las funciones catalogo_inegi() y enoe(). Cortesía de Villiem (https://twitter.com/villicanaem).
  • Nota de la versión 1.1.3. INEGI terminó de trasladar algunos repositorios de su versión beta a su versión estable. Esto afectó los URL de las funciones para el Censo y la ENOE. La versión beta 1.1.3 arregla este problema.
install.packages("devtools")
devtools::install_github("crenteriam/importinegi")
library(importinegi)

importinegi's People

Contributors

crenteriam avatar villiem avatar

Stargazers

Héctor  avatar Francisco G. Villarreal avatar Federico Veneri avatar Javier {∅, Rdz} avatar Andrei-WongE avatar  avatar Marco Julio Del Moral Argumedo avatar  avatar  avatar

Watchers

James Cloos avatar

Forkers

alfcano villiem

importinegi's Issues

Error in foreign::read.dbf(paste0(zipdir, "\\", i), as.is = TRUE) : unable to open DBF file. SOLVED!!!

Hola, he corrido estos comandos:

library ("importinegi")
enoe(year = 2019, trimestre = "trim4", integrar = FALSE)

Pero he obtenido esto:

probando la URL 'http://www.inegi.org.mx/contenidos/programas/enoe/15ymas/microdatos/2019trim4_dbf.zip'
Content type 'application/x-zip-compressed' length 26128286 bytes (24.9 MB)
==================================================
downloaded 24.9 MB

Error in foreign::read.dbf(paste0(zipdir, "\\", i), as.is = TRUE) : 
  unable to open DBF file

He revisado en https://rdrr.io/cran/foreign/man/read.dbf.html ,
pero sólo encontré:

View source: R/dbf.R
Description
The function reads a DBF file into a data frame, converting character fields to factors, and trying to respect NULL fields.
The DBF format is documented but not much adhered to. There is is no guarantee this will read all DBF files.

Muchas gracias por su atención, cualquier guía que me pueda proporcionar es altamente apreciada.

Alfonso

catalogo = catalogo_inegi() doest not display catalog (i share solution)

This function still does not display the catalogue, but I have modified it, so I am sharing the code:

catalogo = function (id = NA)
{
open.id = paste0("http://www3.inegi.org.mx/rnm/index.php/catalog/",
id)
if (!is.na(id)) {
shell.exec(open.id)
}
else {
Catalogo = tempfile()
utils::download.file("http://www3.inegi.org.mx/rnm/index.php/catalog/export/csv?ps=500&",
Catalogo)
Catalogo = utils::read.csv(Catalogo, encoding = "UTF-8")
names(Catalogo)[names(Catalogo) == "X.U.FEFF.id"] <- "id"
Catalogo = base::subset(Catalogo, select = c("id",
"title"))
return(Catalogo)
}
}

Función: enoe(year = 2020, trimestre = "trim3", integrar = TRUE) no funciona. SOLVED

Hello, thanks for all the work you've put into this.
I've found this issue,

enoe(year = 2020, trimestre = "trim3", integrar = TRUE)

probando la URL 'http://www.inegi.org.mx/contenidos/programas/enoe/15ymas/microdatos/2020trim3_dbf.zip'
Content type 'text/html' length 2263 bytes
==================================================
downloaded 2263 bytes

Error in get(ls(pattern = "dt\\.viv")) : primer argumento inválido
Además: Warning message:
In utils::unzip(temp.enoe, exdir = zipdir) :
  error 1 al extraer del archivo zip
Error in get(ls(pattern = "dt\\.viv")) : primer argumento inválido

¿It's possible to fix it?
¿Am I doing something wrong?

Update:
OK, I've added "enoe_n_2020_", instead of only the number of the year :

enoe <- enoe(year = "enoe_n_2020_", trimestre = "trim3", integrar = TRUE)

but I get another error:

probando la URL 'http://www.inegi.org.mx/contenidos/programas/enoe/15ymas/microdatos/enoe_n_2020_trim3_dbf.zip'
Content type 'application/x-zip-compressed' length 22075762 bytes (21.1 MB)
==================================================
downloaded 21.1 MB

Error in foreign::read.dbf(paste0(zipdir, "\\", i), as.is = TRUE) : 
  unable to open DBF file

Regards
Alfonso

censo_poblacion_iter does not download data for 2015

I have downloaded data for 2010 and now I am trying to download data for 2015, but it appears an error.

My code is the following:
data = censo_poblacion_iter(year = 2015, estado = "Nacional",
totalestado = TRUE, totalmunicipio = FALSE,
localidades = FALSE)

and the error is the following:

**trying URL 'http://www.inegi.org.mx/contenidos/programas/ccpv/2015/microdatos/iter/00_nacional_2015_iter_dbf.zip'
Content type 'text/html' length 2263 bytes

downloaded 2263 bytes

Error in path.expand(file) : invalid 'path' argument
In addition: Warning message:
In utils::unzip(censo.temp.iter) : error 1 in extracting from zip file**

integrar= TRUE not useful with "survey" package

Hi,
I've just wanted to comment:
I've used the survey package with function "enoe" argument "integrar= TRUE". But the way it integrates the data, is not compatible with the "survey" package.

For example, it is explicit on the documentation: https://www.inegi.org.mx/contenidos/programas/enoe/15ymas/doc/con_basedatos_proy2010.pdf

that you must filter first SDEM table, in this case "RESULTADOS DE LA ENCUESTA NACIONAL DE OCUPACIÓN Y EMPLEO, NUEVA EDICIÓN CIFRAS DURANTE EL TERCER TRIMESTRE DE 2020". And do something like:

SDEM_PEAt320.df <- subset(SDEMT320.df, subset=(r_def == "Entrevista completa") & (c_res != "Ausente definitivo") & (eda >11) & (eda!=99))

And on tables COE 1 and COE 2:

COE2t320.data[["r_def"]] <- COE1t320.data[["r_def"]]

COE1t320.df <- subset(COE1t320.data, subset=r_def == "Entrevista completa")

COE2t320.df <- subset(COE2t320.data, subset=r_def == "Entrevista completa")

And then integrate the data, for example:

library(dplyr)
SDEM_COE1.df<-right_join(SDEM_PEAt320.df,COE1t320.df,
    by=NULL,
    copy=FALSE)
SDEM_ENOEN.df<-right_join(SDEM_COE1.df,COE2t320.df,
    by=NULL,
    copy=FALSE)

Finally:

SDEM_ENOEN15.df <- subset(SDEM_ENOEN.df, subset=eda>14)

Then, it is possible to create the survey design:

library(survey)
design.1 <- svydesign( id = ~upm, 
            weights = ~fac_tri, 
            data = SDEM_ENOEN15.df, 
            nest=TRUE )
            

Only then it is possible to obtain the correct expanded results:

Media de la edad y ES

  • Variable de entrada: eda
  • svydesign: design.1

  mean SE
eda 41.2426296274202 0.10941626722319

And:

Total por sexo

  • Variable de entrada: sex.r
  • svydesign: design.1

  Total SE
sex.rMujer 50382749 830895.979424987
sex.rHombre 45956648 755210.532778965

As appears in: https://www.inegi.org.mx/contenidos/programas/enoe/15ymas/doc/enoe_n_nota_tecnica_trim3_2021.pdf (There also appears info on 2020 3rd Trim )

I hope this is useful to somebody.

Cheers!!

Data not found

The server of INEGI has changed. The http links to the zip files for download are not longer correct, making this tool obsolete (?).

Cannot download data for mac with catalogo_inegi

Every time I try to download data I get the following error. I hope you can update this function for a mac.

catalogo_inegi(id = 632)
Error in shell.exec(open.id) : could not find function "shell.exec"

dependency on retiring spatial infrastructure packages

You will be aware, for example from:
https://r-spatial.org/r/2022/04/12/evolution.html,
https://r-spatial.org/r/2022/12/14/evolution2.html,
https://r-spatial.org/r/2023/04/10/evolution3.html and
https://rsbivand.github.io/csds_jan23/bivand_csds_ssg_230117.pdf and
perhaps view https://www.youtube.com/watch?v=TlpjIqTPMCA&list=PLzREt6r1NenmWEidssmLm-VO_YmAh4pq9&index=1
that rgdal, rgeos and maptools will be retired this
year, in October 2023.

importinegi imports 'rgdal' using rgdal::readOGR found by pkgapi not in NAMESPACE, line 24 in R/sig_caminos_extrae.R and lines 137-9 in sig_marcogeo.R. sf::st_read, terra::vect are possible replacements, from which you can coerce back to the original object representation. Please fix best by June, latest October 2023.

catalogo_inegi() does not show any data

The catalogo_inegi() function does not show any data, instead the following error appears when running:

data = catalogo_inegi() #496 catálogos (#632 Censo de Población y Vivienda 2020)
trying URL 'http://www3.inegi.org.mx/rnm/index.php/catalog/export/csv?ps=500&'
Content type 'text/csv;charset=UTF-8' length unknown
downloaded 158 KB

Error in [.data.frame(x, r, vars, drop = drop) :
undefined columns selected

I check the function and the problem has to do with the defined columns to be selected:

select = c("id",
"surveyid", "titl", "data_coll_start",
"data_coll_end", "created", "changed")

Whereas the actual names of the columns are the following:

id,idno,title,nation,authoring_entity,year_start,year_end,created,changed

Therefore, you only need to update the right name of the columns in the function.

I hope that info helps to solve the issue!

Best

Orlando

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.