The basicity of aniline derivatives decreases as electron-withdrawing groups like NO2 (in p-nitroaniline) decrease the electron density on the nitrogen atom. On the other hand, electron-donating groups like methyl (in p-toluidine) and dimethyl groups (in N,N-dimethyl-p-toluidine) increase the electron density, enhancing the basicity. Hence, the order of basicity is:
\[
{N,N-dimethyl-p-toluidine (II)}>{p-toluidine (I)}>{aniline (IV)}>{p-nitroaniline (III)}
\]