|Title||Adding extra observations when coding an ado-file|
|Author||William Gould, StataCorp|
|Date||December 1999; update May 2015|
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 + L 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.
Another approach is to expand the data, which can be done in one statement:
expand 2 in l
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