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
Output results from looped cox regressionHello, I am fairly new to Stata. I need to run a cox regression over 248 variables and I want to the…
Contradictory outcome xtologit OR vs margins dydx(*)Hi Stata users, Please I'd help for this issue. I run a xtologit model where my dependent variable i…
Time windowFama-MacBeth Regression (fmb)Hello everyone, I am trying to run a 2 step fama macbeth regression for financial data, for which t…
Import data from an ESRI geodatabaseHello, I would like to know if it is possible to connect STATA with a geodatabase ESRI. I do not wh…
Covariance matrix for two different modelsIs there a way to get covariance matrix of coefficients from two different models? I am trying to ca…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a loop to generate summary data
Post a Comment