I feel very sorry for not updating this site for a long time. I have too much work to do lately and in the past year, I’ve spent some time developing my new hobby: trading in the capital market. I will talk more trading and comparing different trading strategies in the future 🙂
Today I will show how to plot maps using Stata. I am definitely not a GIS guru but for people who specialize in Urban or real estate economics, plotting maps by using stata can become very handy, especially for empirical work. All you need is to install 2 ado files in Stata: spmap and shp2dta.
Typing “ssc install spmap” and “ssc install shp2dta” in STATA.
For illustration purpose, I will use the City of Vancouver property tax report data from the City of Vancovuer Open Data Catalogue. The download link is here . We are going to make a map of average land value by FSA in Vancouver. FSA means Forward sortation areas, which is actually just the first 3 digit of the postal code.
We use the Year 2017 data. (download the csv file). The data set includes different variables and it is a dataset with hundreds of thousands of observations. We focus on the single variable: current_land_value
The next data file we need to download is the shapefile, which is downloadable on the Statistics Canada website: http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm
we download the one labeled as “Forward sortation areas”
Plot Our Map
Put them into the same folder . In STATA, we declare the directory of that folder by using the cd command.
The next step is to use the following command:
“shp2dta using gfsa000b11a_e, database(map) coordinates(coord) ”
The code above converts the shapfile into the Stata data files. The coordinate file is named “coord” while the database file is named “map”
Next step: import the csv file into STATA and create the FSA identifier variable by typing the following:
“gen CFSAUID = substr(property_postal_code,1,3)”
We need to name it as CFSAUID instead of FSA because in our map data, the variable name is CFSAUID. In order to marge the 2 dataset based on FSA, we need them to be named as the same.
Next, we calculate the average land value for each FSA and collapse it into FSA level by typing:
“collapse current_land_value, by(CFSAUID)”
Next, we merge the dataset by typing:
“merge 1:1 CFSAUID using map.dta”
Next, we use the spmap command:
“spmap current_land_value using coord if CFSAUID !=”V6T”, id(_ID) fcolor(Blues) title(“Average land price by FSA in Vancouver in 2017”) ”
we exclude the V6T area for the graphical purpose (or you can include it but you will see what I meant if you include V6T area…)
Below is the map:
The map looks pretty nice, right? As you can see…the eastern part of Vancouver City and the west side of Vancouver City look drastically different in terms of land value!
Next post, I will talk more about trading and possibly, part 2 of markov-switching regression. Stay tuned!