title: Stata: extract p-values and save them in a list
body: <p>This may be a trivial question, but as an R user coming to Stata I have so far failed to find the correct Google terms to find the answer. I want to do the following steps:</p>
  
  <ul>
  <li>Do a bunch of tests (e.g. lrtest results in a foreach loop)</li>
  <li>Extract the p-value from each test and save them in a list of some kind</li>
  <li>Have a list I can do further operations on (e.g. perform multiple comparison correction)</li>
  </ul>
  
  <p>So I am wondering how to extract p-values (or similar) from command results and how to save them into a vector-like object that I can work with. Here is some R code that does something similar:</p>
  
  <pre><code>myData &lt;- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10)) ## generate some data
  pValue &lt;- c()
  for (variableName in c("b", "c")) {
      myModel &lt;- lm(as.formula(paste("a ~", variableName)), data=myData) ## fit model
      pValue &lt;- c(pValue, coef(summary(myModel))[2, "Pr(&gt;|t|)"]) ## extract p-value and save in vector
  }
  pValue * 2 ## do amazing multiple comparison correction
  </code></pre>
  
  <p>To me it seems like Stata has much less of a 'programming' mindset to it than R. If you have any general Stata literature recommendations for an R user who can program, that would also be appreciated.</p>