Rare earths and their compounds show many interesting physical phenomena caused by the complex electronic structure related to f electrons. External pressure can affect the hybridization between 5d band electrons and the more atomic-like 4f ones, giving rise to intermediate valence behaviour. Resonant x-ray emission spectroscopy (RXES) has been shown to be a very effective tool for probing the mixed valence ground state under pressure. A RXES experiment detects the x-ray emission that follows decay into a resonantly created core hole. Being a photon- in-photon-out spectroscopic technique, it is not hindered by the presence of the pressure cell. In the case of rare earths we chose to detect the 3d-2p x-ray emission following a 2p-5d resonant excitation process. The divalent and trivalent components of the ground state are separately enhanced because they resonate at different incident photon energies. Very good precision in the determination of even small changes of valence is reached. We will present experimental results on ytterbium compounds (YbAl2 and YbS), as well as recent data on the valence state of SmS in the gold phase, that have allowed us to unveil the progressive valence change towards the completion of trivalency. The spectral changes and the way to extract the valence from measured spectra will be discussed.