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: Data structure - left adjusted - numeric variable


From   Matthew White <[email protected]>
To   [email protected]
Subject   Re: st: Data structure - left adjusted - numeric variable
Date   Tue, 3 Apr 2012 19:55:25 -0400

Hi Danny,

Maybe Mata would be easiest here?

clear
input id f1 f2 f3 f4 f5 f6
1 . 12 23 . . 56
2 . 62 . . . .
3 881 . 453 34 55 .
4 . 92 . . . .
5 . 62 . . . .
6 . . . . . 67
7 91 . . . 87 .
8 . . . 66 . .
9 . . 53 . . 76
end

mata:

X = st_data(., .)'
Y = J(rows(X), 0, .)
missing = X :== .
n = 1::rows(X)
for(i = 1; i <= cols(X); i++) {
	Y = Y, X[order((missing[., i], n), 1..2), i]
}
Y = Y'

st_store(., ., Y)

end

Best,
Matt

On Tue, Apr 3, 2012 at 6:20 PM, Danny <[email protected]> wrote:
> Dear all,
>
> I would like to re-structure my panel data which currently sit in the fixed column format (looks like the 1st part of my syntax) to left adjusted format (looks like the 2st part of my syntax).
>
> It would be much appreciated if anyone knows any easy syntax or program can handle it?.
>
> **1st part
> clear
> input id f1 f2 f3 f4 f5 f6
>  1  . 12 23  .  . 56
>  2  . 62  .  .  .  .
>  3 881  . 453 34 55  .
>  4  . 92  .  .  .  .
>  5 . 62  .  .  .  .
>  6  .  .  .  .  .  67
>  7 91  .  .  .  87  .
>  8  .  .  .  66  .  .
>  9  .  . 53  .  . 76
>  End
>
>
> **2nd part
> clear
> input id t1 t2 t3 t4 t5 t6
>  1  12 23  56 . . .
>  2  62  .  .  .  . .
>  3 881 453 34 55  . .
>  4  92  .  .  .  . .
>  5  62  .  .  .  . .
>  6  67 .  .  .  .  .
>  7 91 87  . .  .  .
>  8  66  .  . .  .  .
>  9  53  76 .  .  .  .
>  End
>
>
> Danny
>
> Data Analyst
> Health Sponsorship Council
> New Zealand
>
>
> *
> *   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/



-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org

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