Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Andrin Foster <akf7@case.edu> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: how to implement a dictionary (aka map, look-up table) |
Date | Sat, 15 Dec 2012 19:45:59 -0500 |
I'm trying to set a value based on observation variables matching relevant dictionary entries. I've tried to implement a dictionary amongst the variables in Stata, however, I can't compare my results to the dictionary because the dictionary entries and results are counted as different observations. my code was: gen Value = MetaValue if X==MetaX & Y==MetaY & Z==MetaZ where the data used was formatted as such: ================================================== X Y Z MetaX MetaY MetaZ MetaValue -------------------------------------------------------------------------------------- 1 5 3 . . . . 3 2 7 . . . . 9 1 4 . . . . . . . 1 1 1 2 . . . 1 1 2 3 . . . 1 2 1 5 ================================================== Running the above code will not output an error code but will instead produce all missing values since the comparisons always resolve to false. In psudocode, Stata is currently running... for i in range observations: Value[i] = MetaValue[i] if X[i]==MetaX[i] & Y[i]==MetaY[i] & Z[i]==MetaZ[i] ...when what I need is... for i in range observations: for k in range dictionary: Value[i] = MetaValue[k] if X[i]==MetaX[k] & Y[i]==MetaY[k] & Z[i]==MetaZ[k] What is the proper function or data format to achieve my goal? I'm using Stata 12 on Mac OS 10.7.5 -- Andrin Knight Foster Case Western '12 Economics, English * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/