Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2015 12:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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
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')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment