Dear Stata Users,
I hope this email finds you well. I'm reaching out seeking assistance with a data retrieval task.
I have a dataset structured as follows:
I aim to download climate data by leveraging the latitude and longitude coordinates of each city. Specifically, I need to access the following API link, iterating/looping through each city:
For instance, for the initial iteration (for London), the link to be utilized is: https://power.larc.nasa.gov/api/temp...=1981&end=2022
Here's the syntax I attempted to use:
Unfortunately, I encountered challenges in obtaining the table like this:
Any guidance or assistance you could provide would be greatly appreciated.
Thank you in advance for your support.
Warm regards,
Meerim
I hope this email finds you well. I'm reaching out seeking assistance with a data retrieval task.
I have a dataset 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 |
For instance, for the initial iteration (for London), the link to be utilized is: https://power.larc.nasa.gov/api/temp...=1981&end=2022
Here's the syntax I attempted to use:
Code:
clear local code "GB" "US" "JP" "FR" "AE" "SG" "DE" local region "Europe" "North America" "Asia" "Europe" "Middle East" "Asia" "Europe" local city "London" "New York" "Tokyo" "Paris" "Dubai" "Singapore" "Berlin" local lat "51.5074" "40.7128" "35.6895" "48.8566" "25.2769" "1.3521" "52.52" local long "-0.1278" "-74.006" "139.6917" "2.3522" "55.2962" "103.8198" "13.405" foreach region in `region' { foreach code in `code'{ foreach name in `name'{ foreach long in `long'{ foreach lat in`lat'{ local opt= cond(`name'=="London", "replace", "append") import delimited"https://power.larc.nasa.gov/api/temporal/monthly/point?parameters=T2M,PRECTOTCORR_SUM,PRECTOTCORR&community=AG&longitude=`long'&latitude=`lat'&format=CSV&start=1981&end=2022", rowrange(12) varnames(12) gen name=`name' gen code=`code' gen region=`region' append using "C:\Users\User\Desktop\precdata.dta" if `opt'=="append" save "C:\Users\User\Desktop\precdata.dta", replace clear local i=`i'+1 di `i' } } } } }
ISO Code | Region | City | 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 |
Any guidance or assistance you could provide would be greatly appreciated.
Thank you in advance for your support.
Warm regards,
Meerim
Comment