Stata
Products Purchase Support Company
Search
   >> Home >> Resources & support >> FAQs >> Adding extra observations when coding an ado-file

How do I add an observation to a dataset when coding an ado-file?

Title   Adding extra observations when coding an ado-file
Author William Gould, StataCorp
Date December 1999

Stata’s input command is not a solution because input does not read the data from the ado-file—it reads the data from the keyboard or the running do-file.

One solution is to use the set obs command, and you could do that by coding

        local new = _N + 1
        set obs `new'

You cannot simply set obs _N+1 because set obs does not allow an expression; set obs wants a number.

You would then follow this with replace ... in l statements to set the values as you wish. (Type “in el”, not the number 1.)

Another approach is to expand the data, which can be done in one statement:

        expand 2 in l

The ending is “in el” and, here, I am duplicating the last observation. The advantage of this duplication is that a certain observation might contain most of the values I already want. If that were the first observation rather than the last, I would type

        expand 2 in 1

(here “in the number 1”) and if that were the third observation, I would type

        expand 2 in 3
FAQs
What's new?
Statistics
Data management
Graphics
Programming Stata
Mata
Resources
Internet capabilities
Stata for Windows
Stata for Unix
Stata for Macintosh
Technical support
Resources & support
FAQs
Technical support
NetCourses
Short courses
Users Group meetings
Statalist
Links
Software updates
Software archives
Customer service
Manuals & supplements
Stata Journal
STB
Stata News
Stata Automation
Plugins

Site overview
Products
Resources & support
Company
Site index

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