Scale following the location of another object
You have to drive one object's scale factor in the Z axis, by the other object's location in the Z axis. This is how you would implement it.

If object A is to be scaled based on object B's z coordinate:


Animate object B's z location by inserting keyframe points appropriately.
With object A selected, in the object properties (or the transform toolbox, press 'N' in the 3D View window), hover over the scale Z box and right-click: select add driver.
Configure the driver menu as follows:


Driver Settings -> Type = Scripted Expression
Expression is the scale value. In the example shown in the screenshot, we add to var (location Z coordinate) 1.0.
Under Add Input Variable, on the drop-down menu, select Transform Channel; Object should be your object B; under Type, select Z Location; finally, set the coordinate system (in the example below is the world space).



Now, object A's scale factor on the Z axis will be equal to object B's location in the global Z axis plus one (expression = var + 1.0) .