Skip to content

Instantly share code, notes, and snippets.

@pbaylis
Created September 11, 2015 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbaylis/15cdc8fd59e1888705ae to your computer and use it in GitHub Desktop.
Save pbaylis/15cdc8fd59e1888705ae to your computer and use it in GitHub Desktop.
Stata program to get relative humidity given temperature and dew point
program define gen_relative_humidity
* Calculate relative humidity given dry bulb temperature and dew point
syntax, DRYbulbtemp(varname) DEWpoint(varname) [GENerate(string)]
* Inputs in F
local T `drybulbtemp'
local TD `dewpoint'
if "`generate'" == "" {
local generate "rel_humidity"
}
capture drop `generate'
* Calculate relative humidity from dry bulb temperature and humidity
* http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html
tempvar TC TDC
gen `TC' = (5/9) * (`T' - 32)
gen `TDC' = (5/9) * (`TD' - 32)
gen `generate' = 100*(exp((17.625*`TDC')/(243.04+`TDC'))/exp((17.625*`TC')/(243.04+`TC')))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment