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: creating new dataset from means of variables by groups


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: creating new dataset from means of variables by groups
Date   Sat, 23 Nov 2013 14:03:50 +0000

<>

clear
input id   country  i1  e1 i2  e2 i3  e3
1  1    0     3     0    2    3   3
2  1    2    10    2    4    6   6
3  2   10   10    4    3  8   8
4  2    7     8    7    2   2   2
end
reshape long e i, i(id) j(value)
drop id
collapse i* e*, by(country value)
reshape wide i e, i(value) j(country)
l

Nick
[email protected]


On 23 November 2013 13:39, Paolo Moncagatta <[email protected]> wrote:
> Hello everyone, I am stuck with a problem and thought maybe someone
> could help me out. This might be a simple issue but I have looked in
> the help, in the statalist, in books, and I still haven't found a
> clear solution. I will try to be as clear as possible in the
> formulation of my problem:
>
> I have a dataset which contains the following variables: id, country,
> importance value_1, evaluation value_1, importance value_2, evaluation
> value_2...importance value_n, evaluation value_n, where the
> "importance" and the "evaluations" are measured from 0-10 and which
> looks like this:
>
> id   country     import     evaluat    import     evaluat    import     evaluat
>                      value1      value1    value2      value2
> value3      value3
> 1        1             0              3           0             2
>       3            3
> 2        1             2             10          2             4
>      6            6
> 3        2            10            10          4             3
>     8            8
> 4        2             7              8          7             2
>      2            2
>
> What I want to do is create a new dataset where the values become the
> cases, and the variables are the mean importance per country and mean
> evaluation per country, something like this:
>
> value     country1     country1     country2     country2
>             mean_imp   mean_eval  mean_imp   mean_eval
> 1                1               6.5              8.5              9
> 2                1                3                5.5             2.5
> 3              4.5              4.5               5                5
>
> Thanks in advance for your help!
>
> Paolo Moncagatta
> Universitat Pompeu Fabra - Barcelona
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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