The Sims 2: FreetimeEdit
In FreeTime, it is in the Miscellaneous area of the Hobbies section of Buy mode, under the name The Formidable Formicarium, and costs §185. Sims can observe the ants, which builds enthusiasm for the Science hobby, and may do so autonomously. Sims can also shake the ant farm, which may allow the ants to escape. Sims will usually not shake an ant farm autonomously, but this has been observed. Several ant farms are located in Aspirational Laboratories, the hobby lot for the Science hobby.
The Sims 3: PetsEdit
In The Sims 3: Pets, it can be found in the "Pet accessories" section of Buy mode, under the name Subterranean Simulation Device, and costs §100. A Sim can only watch the ant farm as the ants move around in it.