Hi all,
I'm fairly new to stata, and still get frustrated when trying to
figure out certain simple things. The major issue is the lack of
ability to create constants, and being forced to only use variables.
I'm probably missing something, but that's what it seems like to me.
Right now, I'm trying to do a primitive regression-type calculation.
I have two columns , Xi and Yi, and would like to calculate:
1) The means for the subsets that belong to
10950(30yrs)>=agegroup>=1825 (5yrs), and 21900>=agegroup>10950,
separately and for both columns.
2) Then calculate the slope (Yi_mean2-Yi_mean1)/(Xi_mean2-Xi_mean2)
The best thing I've come up with so far is to generate temporary
variables with NA's where not defined using statements like:
gen Xi_mean1 = (sum) Xi if agegroup >=1825 & agegroup <=10950
replace Xi_mean1=Xi_mean1/6
,and then calculating 2) refering to a specific entry in the columns
of the temporary variables with subsetting. However, Because I can't
know which row number contain a real value (everything is taking place
inside a .do file), and since I'm dealing with constants, this
roundabout way bothers me.
Is there a more "natural" way to do things?
Data is at the end of this message, tab separated.
Thanks in advance!
best
Gustaf
--
email:[email protected]
tel: +46(0)703051451
address: Kantorsgatan 50:190 75424 Uppsala Sweden
---------
agegroup Dx px N_exact N_plus Dx_plus Xi Yi
"Under 1 year" 65 1941.021 54733.75 377 .0068879
"1-4 yrs" 83 8176.678 1011.77 52792.73 312 .0059099 .0191649
"5-9 yrs" 12 9764.077 1794.075 44616.05 229 .0051327 .0402114
"10-14 yrs" 7 8335.471 1809.955 34851.97 217 .0062263 .0519326
"15-19 yrs" 13 6162.906 1449.838 26516.5 210 .0079196 .0546768
"20-24 yrs" 11 4248.53 1041.144 20353.6 197 .0096789 .0511528
"25-29 yrs" 14 3624.372 787.2902 16105.07 186 .0115492 .0488846
"30-34 yrs" 18 3009.719 663.4091 12480.7 172 .0137813 .0531548
"35-39 yrs" 17 2486.2 549.5919 9470.976 154 .0162602 .0580291
"40-44 yrs" 17 1885.127 437.1327 6984.776 137 .0196141 .0625836
"45-49 yrs" 16 1292.577 317.7704 5099.649 120 .023531 .0623122
"50-54 yrs" 14 857.0027 214.958 3807.072 104 .0273176 .0564628
"55-59 yrs" 5 647.1109 150.4114 2950.07 90 .0305078 .0509857
"60-64 yrs" 7 684.2745 133.1385 2302.959 85 .036909 .0578119
"65-69 yrs" 12 547.0876 123.1362 1618.684 78 .0481873 .0760718
"70-74 yrs" 12 383.9042 93.09918 1071.597 66 .0615903 .0868789
"75-79 yrs" 17 283.4497 66.73539 687.6925 54 .0785235 .0970425
"80-84 yrs" 11 185.6701 46.91198 404.2428 37 .0915292 .116049
"Above 85 years" 26 218.5736 40.42437 218.5727 26 .1189536 .184947
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/