Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating a panel data structure

    Dear community members,

    I have city-level data covering the period 2019, 2020, 2021, 2022, and 2023 regarding the association between exposure to climate hazards (clim_hazard) and adaptation actions ("adapt_act"). I've observed numerous instances where the same city appears across multiple time periods, experiencing similar or different hazards within and between years. To illustrate the structure of the data, I've included an example dataset featuring cities from two countries, Albania and Nigeria. For instance, in the provided data, the "City of Tirana" in Albania encountered three distinct climate hazards in 2019. The "Municipality of Tirana" only faced air pollution in 2022 but experienced three other hazards in 2023. You can see a similar case for cities in Nigeria.

    Code:
     dataex year city_name country clim_hazard adapt_act  if country_n==1 | country_n==74
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float year str87 city_name str52 country str364 clim_hazard str607 adapt_act
    2019 "City of Tirana"                  "Albania" "Extreme hot temperature > Heat wave"              "Green roofs/walls"                                                             
    2019 "City of Tirana"                  "Albania" "Extreme Precipitation > Rain storm"               "Other: Flood protection"                                                       
    2019 "City of Tirana"                  "Albania" "Water Scarcity > Drought"                         "Other: Urban water spaces"                                                     
    2022 "Municipality of Tirana"          "Albania" "Air pollution"                                    "Early warning and response systems"                                            
    2023 "Municipality of Tirana"          "Albania" "Extreme heat"                                     "Early warning and response systems"                                            
    2023 "Municipality of Tirana"          "Albania" "Other, please specify: Air Quality"               "Community engagement/education"                                                
    2023 "Municipality of Tirana"          "Albania" "Heavy precipitation"                              "Other, please specify: URBACT - Lets Go Circular Project"                      
    2019 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Flash / surface flood" "Other: Desiliting of drains, expansion of drainages and canals"                
    2019 "City of Lagos"                   "Nigeria" "Extreme hot temperature > Heat wave"              "Sea level rise modelling"                                                      
    2019 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Coastal flood"         "Community engagement/education"                                                
    2019 "City of Lagos"                   "Nigeria" "Extreme hot temperature > Heat wave"              "Tree planting and/or creation of green space"                                  
    2020 "City of Ibadan"                  "Nigeria" "Extreme Precipitation > Rain storm"               "Flood mapping"                                                                 
    2020 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Flash / surface flood" "Community engagement/education"                                                
    2020 "City of Lagos"                   "Nigeria" "Extreme hot temperature > Heat wave"              "Sea level rise modelling"                                                      
    2020 "Abuja Federal Capital Territory" "Nigeria" "Chemical change > Atmospheric CO2 concentrations" "Flood mapping"                                                                 
    2020 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Coastal flood"         "Tree planting and/or creation of green space"                                  
    2020 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Coastal flood"         "Other, please specify: Desiliting of drains, expansion of drainages and canals"
    2021 "City of Ibadan"                  "Nigeria" "Extreme Precipitation > Rain storm"               "Flood mapping"                                                                 
    2021 "City of Lagos"                   "Nigeria" "Extreme hot temperature > Heat wave"              "Other, please specify: Desiliting of drains, expansion of drainages and canals"
    2021 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Flash / surface flood" "Sea level rise modelling"                                                      
    2021 "City of Lagos"                   "Nigeria" "Extreme hot temperature > Heat wave"              "Community engagement/education"                                                
    2021 "City of Lagos"                   "Nigeria" "Flood and sea level rise > Coastal flood"         "Tree planting and/or creation of green space"                                  
    2021 "Abuja Federal Capital Territory" "Nigeria" "Chemical change > Atmospheric CO2 concentrations" "Flood mapping"                                                                 
    2022 "City of Ibadan"                  "Nigeria" "River flooding"                                   "Land zoning laws (including restrict development in at risk areas)"            
    2022 "City of Ibadan"                  "Nigeria" "Biodiversity loss"                                "Land zoning laws (including restrict development in at risk areas)"            
    2023 "City of Ibadan"                  "Nigeria" "Biodiversity loss"                                "Land zoning laws (including restrict development in at risk areas)"            
    2023 "City of Lagos"                   "Nigeria" "Coastal flooding (incl. sea level rise)"          "Community engagement/education"                                                
    2023 "City of Lagos"                   "Nigeria" "Urban flooding"                                   "Community engagement/education"                                                
    2023 "City of Lagos"                   "Nigeria" "Extreme heat"                                     "Community engagement/education"                                                
    2023 "City of Ibadan"                  "Nigeria" "Urban flooding"                                   "Land zoning laws (including restrict development in at risk areas)"            
    2023 "Abuja Federal Capital Territory" "Nigeria" "Extreme heat"                                     "Green infrastructure"                                                          
    end


    My query revolves whether I can construct panel data without losing observations, considering that certain cities appear multiple times within the same years, as well as the varying types of hazards to which cities are exposed. I would greatly appreciate any guidance or advice you can offer on this matter.

  • #2
    Bahre:
    welcome to this forum.
    First, you should make your variables suitable for -xt- commands (I recommend you to take a look at -encode- entry in Stata .pdf manual and see its drawbacks, though):
    Code:
    . encode city_name, g(city_id)
    
    . encode country , g( country_id)
    
    . encode clim_hazard , g( clim_hazard_cat )
    
    . encode adapt_act , g( adapt_act_cat )
    Then you have to -xtset- your data with -panelid- only, to avoid Stata complaining about -repeated time values within panel- (I assume that -city_id- is your -panelid-)M
    Code:
    xtset city_id
    While this trick makes time-series operators (such as lags and leads) unavailable, you can still add -i.year- in the right-hand side of your regression equation.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Dear @Carlo,

      I appreciate your prompt response. I had already encoded the variables you mentioned, but my idea was to declare the panel using both the panel ID (city ID) and the time variable (year). Now, it functions correctly with your recommendation. Thank you very much.

      Comment

      Working...
      X