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 on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: data management questions


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: data management questions
Date   Sat, 21 Aug 2010 13:49:40 +0200

<>


ad (1):


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

inp byte ID int NID
1 100
2 100
3 104
4 102
5 104
end

list, noo

preserve
bys NID: keep if _n==1
drop ID
l
save mynids, replace
restore
***********


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Bai
Sent: Samstag, 21. August 2010 12:52
To: statalist@hsphsun2.harvard.edu
Subject: st: data management questions

Dear all,

     I have two questions regarding data management, and would 
appreciate it if anybody can help.

(1) If I have a datafile like this:

 ID(individual id)         NID(neighborhood id)
1                                   100
2                                   100
3                                   104
4                                   102
5                                   104

How can I create a datafile for neighborhood ID variable like this?:
NID
100
102
104

(2) Now since I have the complete list of NIDs (suppose there are 100 
neighborhoods), I'd like to use this NID file to merge with another 
data file (dataset Two, which has neighborhood ID variable and 
time-varying variables. Dataset Two has 200 neighbors) like this:
NID                year              var1
100                1                   850
100                2                   600
101                1                   90
102               1                   600
102                2                  400
103                1                  500
103                2                  400
103                3                  506


  I only want to keep the 100 neighborhoods that appear in the NID file, 
What syntax I can use to merge the two data files for the 100 
neighbors? Thank you very much.

*
*   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