Download a PDF of this worksheet

Data

We have several datasets we will be looking at in this workshop. These are available in the class middfiles folder.

Working in QGIS

  1. Open QGIS, go to Project > New, then Save As, and save the QGIS file in your working directory.
  2. Add your first layer: Layer > Add Layer > Add Raster Layer
    1. The raster layer you’re going to add is:
      /2010nighttime_lights/F182010.v4d_web.stable_lights.avg_vis.tif.gz
    2. Right-click on the layer, and open the Properties; change the layer name to something easier to read, like nighttime_lights
  3. Add your second layer: Layer > Add Layer > Add Vector Layer
    1. The vector layer you’re going to add is:
      /nigeria_administrative_boundaries/gadm36_NGA_shp.zip
    2. Add Layer ID “1” - the one with 37 features
    3. Right-click on the layer, and open the Properties; change the layer name to something easier to read, like nigeria_state_borders
    4. Under Symbology, click on “Simple Fill” > change the “Fill Color” to “Transparent Fill” (click the small down arrow)
    5. Under Symbology, change the “Stroke Color” to something easier to see on the black background (e.g. Red)
    6. Right-click the state borders layer and “Zoom to Layer”
  4. Add the last layer: Layer > Add Layer > Add Vector Layer
    1. The vector layer you’re going to add (as a directory) is:
      /Flares_Nigeria_1/
  5. Now, to account for the flares:
    1. Vector > Geoprocessing Tools > Difference
    2. Your “Input Layer” is the Nigerian state borders, your “Difference Layer” is the Flares layer
    3. Rename your layer, fix the fill/stroke colors
  6. Now, to get rid of the extraneous nighttime light data:
    1. Raster > Extraction > Clip Raster by Mask Layer
    2. Your nighttime lights layer is the “Input Layer,” the clipped Nigerian state borders layer from the last step is the “Mask Layer”
    3. Rename your layer
  7. Now, to add data about the median light level within a state’s borders to the state borders table
    1. Processing > Toolbox > Raster Analysis > Zonal statistics
    2. Raster layer is your clipped nighttime lights from step 6, “Vector layer containing zones” is your clipped state borders layer
    3. add an appropriate prefix to the output columns
  8. We need to do some light data editing before we export our CSV
    1. Open up the attribute table for the clipped state borders layer
    2. Toggle editing mode, toggle multi-editing mode
    3. In the drop-down, choose NAME_1, and enter lower( NAME_1) in the box; click “Update All”
    4. Now turn off multi-editing mode, click on the entry for federal capital territory, and change it to fct-abuja (to match the DHS dataset)
    5. Open up Properties > Source Fields, double-click on NAME_1 and rename it sstate to match the DHS dataset
  9. Now to output the table we’ve created as a CSV
    1. Right-click on the layer > Export > Save Features As
    2. Choose CSV as the format, name the output file, click OK
  10. Before you quit QGIS, you need to save any “temporary scratch layers” that you want to keep > do this!

Working in Stata

  1. Open the individual DHS dataset:
    use "/Users/rclement/Desktop/2018_econ212_gis/2010dhs_individual_nigeria/NGIR61FL.DTA"
  2. Collapse your variable of interest by state:
    collapse variable, by(sstate)
  3. Rename your collapsed variable to something more understandable:
    rename variable meaningful_name
  4. Decode your state variable to a string to match the nightlights data:
    decode variable, generate(new_variable)
  5. Rename your new string state variable to match the nightlights data:
    drop variable
    rename new_variable variable
  6. Save your collapsed dataset:
    save "/2010dhs_individual_nigeria/collapsed_dataset.dta", replace
  7. Bring in your nightlights dataset:
    import delimited "/directory_location/nightlights.csv", encoding(ISO-8859-1)clear
  8. Merge with your collapsed data:
    merge 1:1 sstate using "/2010dhs_individual_nigeria/collapsed_dataset.dta"
  9. Do your analysis!

References

Gandhi, U. (2017a). Getting Started With Python Programming — QGIS Tutorials and Tips. Getting Started With Python Programming. Retrieved from https://www.qgistutorials.com/en/docs/getting_started_with_pyqgis.html

Gandhi, U. (2017b). Introduction — QGIS Tutorials and Tips. Introduction. Retrieved from http://www.qgistutorials.com/en/docs/introduction.html

Lowe, M. (2014). Night Lights and ArcGIS: A Brief Guide.

Mcleod, D. (2016). Fordham Department of Economics: ECON 5740 GIS Mapping in Stata and R. ECON 5740 GIS Mapping in Stata and R. Retrieved from http://darrylmcleod.com/gis/gis-for-economists/

Mellander, C., Lobo, J., Stolarick, K., & Matheson, Z. (2015). Night-Time Light Data: A Good Proxy Measure for Economic Activity? PLOS ONE, 10(10), e0139779. https://doi.org/10.1371/journal.pone.0139779

Nigmatulina, J. (2017). Nighttime Lights - How are they useful? Blog. University of Oxford & the London School of Economics and Political Science Urbanisation in Developing Countries. Retrieved from https://urbanisation.econ.ox.ac.uk/blog/nighttime-lights-how-are-they-useful-dzhamilya-nigmatulina

Official QGIS 3.x Training Material. (2018). Training material. Retrieved from https://www.qgis.org/en/site/forusers/trainingmaterial/index.html