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
How to plot differences in means for diff-in-diff common trend (from Bleakeley & Chin (2004))Dear Stata community, This is my first post on the forum. I'm struggling to recreate figure 1 from …
Save t-statistic output for all observations (function statsby)Hi all, I would like to save all the t-statistics as output for all of my regression observations u…
aweight, pweight or fweight? What to use for WLS?Dear all, I would like to apply a weighted least squares model but I do not know which weight to us…
Frequency for distributions of t-statisticDear everyone, I have data like this Code: * Example generated by -dataex-. To install: ssc instal…
Removing all observations for and individual in a panel when one year has missing values.I have a panel where each individual is recorded over three round - r3, r4, r5. If for instance, an …
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to generate summary data
Post a Comment