To fully utilize the hierarchical memory on modern machines, hierarchical data placement reorganizes program data in many layers of data blocks, which exploit data locality at all memory levels. Manually designed methods have been used in at least three important application domains---matrix operations, N-body simulation, and search trees---by different research groups using very different data layouts. This paper presents a new method for hierarchical data placement. The method is based on the reference affinity model, which captures the temporal pattern in program computation and converts it into the spatial relation in program data. The method is applicable to any sequential programs. It is polynomial time. It automatically gives the hierarchical data layout not only for cases reported by previous studies but also for other important problems. The new results reveal strong relations between computation and data and therefore should help to improve the management of data as well as the design of compilers and programming languages.