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
Controlling for time vs. clustered/robust SEConducting a regression on panel data using xtreg... can someone help me out with the theory behind …
margins plot interpretation for continuous variablesHi there, I have just done a plot of my margins for how the effect of savings rate on investment ra…
rollregHi. I'm using rollreg. There are a number of important (mutually exclusive) parameters to set: move…
Fixing the x-axis range for combined (scatter and line) graphsDear All, When I plot the below graphs, I am not able to arrange the x axis range. I want it to be m…
estpost ttest with multiple conditions and columnsDear Statalist Community, I'm looking to make a summary statistics table for some of my key variabl…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to generate summary data
Post a Comment