We formulate the thermodynamics of economic systems in terms of an arbitrary probability distribution for a conserved economic quantity. As in statistical physics, thermodynamic macroeconomic variables emerge as the mean value of microeconomic variables, and their determination is reduced to the computation of the partition function, starting from an arbitrary function. Explicit hypothetical examples are given which include linear and nonlinear economic systems as well as multiplicative systems such as those dominated by a Pareto law distribution. It is shown that the macroeconomic variables can be drastically changed by choosing the microeconomic variables in an appropriate manner. We propose to use the formalism of phase transitions to study severe changes of macroeconomic variables.