Dear Stata Users,
I hope this message finds you in good spirits.
As I'm relatively new to Stata, despite reading related manuals and posts I could not create a workable syntax.
I'm unsure about the best approach to rectify this issue and would greatly appreciate any guidance or suggestions you could offer in this regard.
I'm reaching out to seek assistance with a task involving data retrieval through looping. I have a dataset containing a list of cities structured as follows:
Code | Region | Name | Latitude | Longitude |
GB | Europe | London | 51.5074 | -0.1278 |
US | North America | New York | 40.7128 | -74.006 |
JP | Asia | Tokyo | 35.6895 | 139.6917 |
FR | Europe | Paris | 48.8566 | 2.3522 |
AE | Middle East | Dubai | 25.2769 | 55.2962 |
SG | Asia | Singapore | 1.3521 | 103.8198 |
DE | Europe | Berlin | 52.52 | 13.405 |
I aim to download climate data by leveraging the latitude and longitude coordinates of each city. Specifically, I need to download data by accessing the API link, looping for each city. For instance, for the first city (for London), the link will be utilized: https://power.larc.nasa.gov/api/temp...=1981&end=2022.
For this, I use the following code:
Code:
import delimited "https://power.larc.nasa.gov/api/temporal/monthly/point?parameters=T2M,PRECTOTCORR_SUM,PRECTOTCORR&community=AG&longitude=-0.1278&latitude=51.5074&format=CSV&start=1981&end=2022", rowrange(12) varnames(12)
Code | Region | Name | Latitude | Longitude | PARAMETER | YEAR | JAN | FEB | … | NOV | DEC | ANN |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1981 | 3.53 | 2.28 | … | 6.58 | 0.19 | 9.15 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1982 | 2.71 | 4.19 | … | 7.75 | 3.48 | 9.87 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1983 | 5.73 | 1.24 | … | 6.61 | 4.83 | 9.77 |
… | … | … | … | … | … | … | … | … | … | … | … | … |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2020 | 5.95 | 6.36 | … | 8.55 | 5.02 | 11 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2021 | 2.81 | 4.6 | … | 6.62 | 6.4 | 10.21 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2022 | 3.91 | 6.58 | … | 9.3 | 4.07 | 11.56 |
Then, in the second loop, I need to download data for the next city in my list (in my case, it is New York) using the same API link but only changing the longitude and latitude within the link:
Code:
import delimited "https://power.larc.nasa.gov/api/temporal/monthly/point?parameters=T2M,PRECTOTCORR_SUM,PRECTOTCORR&community=AG&longitude=-74.006&latitude=40.7128&format=CSV&start=1981&end=2022", rowrange(12) varnames(12)
As a result, I need to create this table:
Code | Region | Name | Latitude | Longitude | PARAMETER | YEAR | JAN | FEB | … | NOV | DEC | ANN |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1981 | 3.53 | 2.28 | … | 6.58 | 0.19 | 9.15 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1982 | 2.71 | 4.19 | … | 7.75 | 3.48 | 9.87 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 1983 | 5.73 | 1.24 | … | 6.61 | 4.83 | 9.77 |
… | … | … | … | … | … | … | … | … | … | … | … | … |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2020 | 5.95 | 6.36 | … | 8.55 | 5.02 | 11 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2021 | 2.81 | 4.6 | … | 6.62 | 6.4 | 10.21 |
GB | Europe | London | 51.5074 | -0.1278 | T2M | 2022 | 3.91 | 6.58 | … | 9.3 | 4.07 | 11.56 |
US | North America | New York | 40.7128 | -74.006 | T2M | 1981 | 3.53 | 2.28 | … | 6.58 | 0.19 | 9.15 |
US | North America | New York | 40.7128 | -74.006 | T2M | 1982 | 2.71 | 4.19 | … | 7.75 | 3.48 | 9.87 |
US | North America | New York | 40.7128 | -74.006 | T2M | 1983 | 5.73 | 1.24 | … | 6.61 | 4.83 | 9.77 |
… | … | … | … | … | … | … | … | … | … | … | … | … |
US | North America | New York | 40.7128 | -74.006 | T2M | 2020 | 5.95 | 6.36 | … | 8.55 | 5.02 | 11 |
US | North America | New York | 40.7128 | -74.006 | T2M | 2021 | 2.81 | 4.6 | … | 6.62 | 6.4 | 10.21 |
US | North America | New York | 40.7128 | -74.006 | T2M | 2022 | 3.91 | 6.58 | … | 9.3 | 4.07 | 11.56 |
Thank you in advance for your support.
Warm regards,
Meerim
Comment