Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: RE: RE: Creating new observations


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: Creating new observations
Date   Tue, 15 Jun 2010 22:38:30 +0200

<>

" It's better to think in terms of new variables, not new observations."



So, Ida, the creation of new variables, as opposed to observations, could be
conducted like this in your case:



***********
clear*

inp str1 Country	byte(Income Population)
A			5				5
B			3				3
N			3				3
end

egen totincAB=total(inlist(Country, "A", "B")*Income)  /* 
*/ if inlist(Country, "A", "B")

egen totpopAB=total(inlist(Country, "A", "B") /* 
*/ *Population) if inlist(Country, "A", "B") 

list, noo
***********


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Dienstag, 15. Juni 2010 22:19
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: Creating new observations

As Martin says, you can do this, but it is not Stataish. 

Stata is not best used as if it were a spreadsheet program, in which you
can tuck all sorts of derivative data and results somewhere else as
extra observations. 

If you do this in Stata, you then have to remember to exclude the new
observations you have created from subsequent commands to avoid double
counting. 

It's better to think in terms of new variables, not new observations. 

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss

This can be done, but is unusual and rare:

***********
clear*

inp str1 Country	byte(Income Population)
A			5				5
B			3				3
N			3				3
end

set obs `=_N+1'


replace Country=Country[1]+"+"+Country[2] in l
replace Income=Income[1]+Income[2] in l
replace Population=Population[1]+Population[2] in l

list, noo
***********

Ida Johnsson

I am new to Stata and have the following problem. How do I create new  
observations if I have panel data, for example

Country		Income			Population
A			5				5
B			3				3
...			...				...
...			...				...
...			...				...
...			...				...
N			3				3


and want to add observations that are grouped values for certain  
countries, for example

Country		Income			Population
A			5				5
B			3				3
...			...				...
...			...				...
...			...				...
...			...				...
N			3				3
A+B			8				8


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index