Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Adding an observation to a dataset


From   "Allan Reese (Cefas)" <allan.reese@cefas.co.uk>
To   "'Statalist (E-mail)" <statalist@hsphsun2.harvard.edu>
Subject   st: Adding an observation to a dataset
Date   Wed, 7 Jun 2006 14:42:51 +0100

To construct a table of various derived statistics, one approach is to collapse the data.  I then wanted an extra line for totals.  Searching help found a function within Mata but otherwise suggested creating a temporary file with one case then appending it to the original.  However, a direct approach worked in a DO file and seems worth documenting on this list:

   local nn=_N+1
   set obs `nn'

The other part of the task, for completeness, includes forming totals of numbers, weights, percentages: 
 
   egen pcbyn = pc(nitem)
   egen totn = sum(nitem)
   egen totnpc = sum(pcbyn)   /* should be 100 */
* Copy column totals down to pseudo-observation (now 'last'). 
   quietly {
      local nn=_N+1
      set obs `nn'
      replace Species = "Total   ...  "   in l
      replace nitem=totn[1]               in l
      replace pcbyn=totnpc[1]             in l
   }
   list species nitem pcbyn

Searching the archive for advice on copying output to Word found a suggestion to use Ctrl/Shift/C which would copy a table with tabs.  Didn't work for me.  Still limited to copying text and formatting in Word as Courier/9pt to get fixed spacing.

Allan
 


***********************************************************************************
This email and any attachments are intended for the named recipient only.  Its unauthorised use, distribution, disclosure, storage or copying is not permitted.  If you have received it in error, please destroy all copies and notify the sender.  In messages of a non-business nature, the views and opinions expressed are the author's own and do not necessarily reflect those of the organisation from which it is sent.  All emails may be subject to monitoring.
***********************************************************************************


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index