Statalist


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

RE: st: Reading data with multiple (and different number of) lines per observation


From   Roy Wada <[email protected]>
To   <[email protected]>
Subject   RE: st: Reading data with multiple (and different number of) lines per observation
Date   Sun, 12 Apr 2009 03:40:17 -0700

 
You should infix twice. Given them household identifiers.
Then -merge- on the id.
 
1. infix according to the household. Drop everything else.
 
drop if later==.
gen id=_n
 
where "later" is any variable containing any of columns 26-84.
Save for later.
 
2. infix according to person level data. After dropping the 
household row (you can firgure that out),
 
gen temp=1 if middle==.
gen id=sum(temp)
 
where "middle" is any variable containing the column 2-25,
meaning it is the indicator row. Now you can drop that, too.
 
drop if middle==.
drop temp
 
3. Use -merge- or -joinby- to put them together on id.
 
You now have one person per line with the household information
next to them. Use -reshape- if you want it the other way.
 
 
> In my dataset, the number of lines varies from observation to
> observation. Im providing an example of how my raw data looks like
> below. For each observation therere 3 pieces of information:
> 1.Household level data (84 characters long, in line 1)
> 2.Indicator of number of person-level records per household (4
> characters long, in line 2)
> 3.Person level data (25 characters long, in lines 3+)
>
> How can I tell Stata to take into account the variability in the number
> of lines per observation?
>
> Example of data structure:
> ---------------------------------------------------------------------------------
> 000010011800111 1140471504000000000 000001171993
> 4
> 0000005237208080100000000
> 0000005237249501000000000
> 0000005237257601100000000
> 0000005237309120100000000
_________________________________________________________________
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1a_explore_042009
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index