loops - Summarize across a thousand variables for each observation in Stata -
i have made loop creates variable, expectedgpa.
so have 1,000 variables each observation, labeled expectedgpa1, expectedgpa2...expectedgpa1000.
i want average , standard deviation expectedgpas each observation.
so if have this
joe 1 2 1 2 4 sally 2 4 2 4 3 larry 3 3 3 3 3 i want variable returned gives
joe 2 sally 3 larry 3 any help?
first, future questions:
please post code showing you've tried. question shows no research effort.
second, clarify terminology:
you created 1000 variables, each 1 corresponding expected gpa. each observation corresponds different person. want, result, three variables. 1 person's id , 2 the mean , sd of gpa (by person). interpretation, @ least.
one solution involves reshaping data:
clear set more off input /// str5 id exgpa1 exgpa2 exgpa3 exgpa4 exgpa5 joe 1 2 1 2 4 sally 2 4 2 4 3 larry 3 3 3 3 3 end list reshape long exgpa, i(id) j(exgpaid) collapse (mean) mexgpa=exgpa (sd) sdexgpa=exgpa, by(id) list instead of collapse, can run by id: summarize exgpa after reshape, doesn't create new variables.
see help reshape, help collapse , help summarize details.
Comments
Post a Comment