title: Stata. How to post a matrix of by-sort? Or how to return values of a matrix?
body: <p>I have the following <code>initial.dta</code> data set:</p>
  
  <pre><code>obs. ID    city       salary
  1    123   Normal       100
  2    124   Paris        120
  3    125   NY           130
  4    122   .a           155
  5    120   Paris        100
  6    128   Chicago      150
  ................
  </code></pre>
  
  <p>Some values of <code>city</code> and <code>salary</code> may be missing (.a). I need to calculate the average salary for each possible city value and post it to a different Stata .dta, so that the new Stata file would look like this:</p>
  
  <pre><code>       city       averageSalary
         Normal       120
         Paris        110
         NY           150
         .a           108
         Chicago      160
           .................
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>clear
  
  postfile myPost city averageIncome using target.dta
  
      use initial, clear
      sort city
      by city: sum salary, meanonly
      post myPost (`r(city)')  (`r(mean)') // This line does not execute.
  
  postclose myPost    
  </code></pre>
  
  <p>What is the problem in here? Please, anybody answer this question. Or leave a comment...</p>