Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: replacing var if it meets criteria


From   "Parker, Sophie" <sophia.parker.09@ucl.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: replacing var if it meets criteria
Date   Sun, 30 Oct 2011 16:32:51 +0000

Hi,

I'm trying to automate the task of having to evaluate a table. For example, I have a bunch of countries with different port names, some of which are missing. I want to replace the missing value with the port that has the highest volume (volume is given by variable totalFixtureCargoSize). In the table below, this would be Arzew: 


 tabulate LoadPort totalFixtureCargoSize if LoadCountry == "ALGERIA"


                      |      totalFixtureCargoSize

            Load Port |    400000    2310000   6.08e+07 |     Total

----------------------+---------------------------------+----------

                ARZEW |         0          0        380 |       380 

               BEJAIA |         5          0          0 |         5 

               SKIKDA |         0         27          0 |        27 

----------------------+---------------------------------+----------

                Total |         5         27        380 |       412 


I.e., if ALGERIA has a missing LoadPort, then it puts in Arzew. This command clearly doesn't work but should give you an idea:

bysort LoadCountry: replace LoadPort = LoadPort if LoadPort = "" & LoadPort = max(totalFixtureCargoSize)








































*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index