Dear StataList
I am new to programming in Stata. I want to write a programme to count the frequency of all different possible values of a variable, and then use the results from that for further computations.
I am stuck at the first step
I have written a loop that takes on each possible value of variable in question (0-77) and counts the number of occurrences for each value:
. forvalues i = 0(1)77 {
2. count if ev_total==`i'
3. local countEV = r(N)
4. display " `i' " "$countEV" , _continue
5. }
The output I get is as follows:
130
0 0 71
1 0 82
2 0 102
3 0 114
4 0 94
.
,
,
Can anyone explain how to get the output to be formatted as follows:
0 130
1 71
Tabulate gives me :
ev_total | Freq. Percent Cum.
------------+-----------------------------------
0 | 130 3.43 3.43
1 | 71 1.88 5.31
2 | 82 2.17 7.47
3 | 102 2.69 10.17
Finally if I can get those values to be correctly displayed how can I write those data to a new datafile?
With thanks in advance
Charles
Related Posts with Creating a loop to generate summary data
Item Response Theory - calculating individual theta scoresI'm looking for some advice on calculating individual theta scores for 900 people who've responded t…
Coding my continous variable to natural logarithmDear All, I am working on research to identify the influential factors of growth ambitions. I have …
Creating a loop to generate summary dataDear StataList I am new to programming in Stata. I want to write a programme to count the frequency…
Splitting a mata functin into partsHi, I am very much a novice using mata, and i am trying to write a small piece of mata to change ro…
3-Dimensional ReshapeHello everyone, Having some difficulties reshaping a data set. I have the following sample data set…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to generate summary data
Post a Comment