Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Inserting non blank observations multiple times


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: Inserting non blank observations multiple times
Date   Fri, 8 Jul 2011 15:14:57 -0400

On Fri, Jul 8, 2011 at 2:48 PM, Bryan Stuart <[email protected]> wrote:
> I have a data set with 94 observations. After each observation, I want
> to enter 761 (non blank) observations. The new observations will be
> the same for each of the original 94 observations. I found the INSOB
> module, which can easily enter blank observations. This isn't what I
> want. I want to move from something like:
>
> original1
> original2
> original3
>
> to something like:
>
> original1
> new1
> new2
> ...
> new761
> original2
> new1
> new2
> ...
> new761
> original3
> ...
>
> Does anyone have suggestions? Thanks in advance.

Hello Bryan,
see this (incredibly inefficient solution):

	clear
	tempfile insert original chunk product

	input str18 make int price
	insert1	1001
	insert2	1002
	insert3	1003
	end
	list
	save "`insert'"

	sysuse auto
	keep make price
	keep in 1/10
	list
	save "`original'"
	
	local c=_N
	drop in 1/`c'
	save "`product'", emptyok

	forvalues i=1/`c' {
	  use "`original'" in `i'
	  append using "`insert'"
	  save "`chunk'", replace
	
	  use "`product'"
	  append using "`chunk'"
	  save "`product'", replace
	}
	
	list, clean

// --------------- The Output is ------------------------------

       make             price
  1.   AMC Concord      4,099
  2.   insert1          1,001
  3.   insert2          1,002
  4.   insert3          1,003
  5.   AMC Pacer        4,749
  6.   insert1          1,001
  7.   insert2          1,002
  8.   insert3          1,003
  9.   AMC Spirit       3,799
 10.   insert1          1,001
 11.   insert2          1,002
 12.   insert3          1,003
 13.   Buick Century    4,816
 14.   insert1          1,001
 15.   insert2          1,002
 16.   insert3          1,003
 17.   Buick Electra    7,827
 18.   insert1          1,001
 19.   insert2          1,002
 20.   insert3          1,003
 21.   Buick LeSabre    5,788
 22.   insert1          1,001
 23.   insert2          1,002
 24.   insert3          1,003
 25.   Buick Opel       4,453
 26.   insert1          1,001
 27.   insert2          1,002
 28.   insert3          1,003
 29.   Buick Regal      5,189
 30.   insert1          1,001
 31.   insert2          1,002
 32.   insert3          1,003
 33.   Buick Riviera   10,372
 34.   insert1          1,001
 35.   insert2          1,002
 36.   insert3          1,003
 37.   Buick Skylark    4,082
 38.   insert1          1,001
 39.   insert2          1,002
 40.   insert3          1,003


>
> Bryan Stuart
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index