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 linearity tests and confidence interval for the thresholds in Threshold of Hansen (1997)?Hello, I am estimating threshold effect of tax revenue on growth for a single country using command…
Keeping duplicate observations with the true value in other variablesHi Stata users, I have a problem looping over string values. I have a data set that contains duplic…
how to create this table?Array I succeed to run these 6 regressions. The first 3 regressions are OLS and the last 3 columns…
Duplication of ID variables in panel dataHi All. I have the following duplication of data in id & p_id, which I need to resolve. This da…
Interaction term insignificance & Marginsplot problemHi all, My initial pooled OLS estimation yields results with statistically significant coefficients…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to generate summary data
Post a Comment