Dear all,

I just was working on excel files (census data) with the following code:

Code:
clear*

ssc install sxpose, replace

cd "/Users/.../Desktop/age"

forvalues i=2/51 {

import excel "/Users/.../Desktop/age/age`i'.xlsx"

drop B C D E F G I J L M O P R S U V X Y AA AB AD AE AG AH AJ AK
drop in 1/5
drop in 2/6
drop in 3/20
drop in 4/11
drop in 5/9

sxpose, clear force
ren (_var1 _var2 _var3 _var4) (Total y25_29 y18_24 median_age)
drop in 1
seq y, f(2010) t(2019)

encode Total, generate(total)
encode y25_29, generate(y25__29)
encode y18_24, generate(y18__24)
encode median_age, generate(median__age)
drop Total y25_29 y18_24 median_age
ren (y25__29 y18__24 median__age) (y25_29 y18_24 median_age)
save "/Users/.../Desktop/age/age`i'.dta", replace

clear*
}
I than wanted to generate a variable "share of people 18-29" using

Code:
g share18_29 = (y18_24 + y25_29)/total
the data of the first observation was (479,755+311,118)/4,785,437 so share18_29 should have been 0.1653 but state calculated it to be 9. I than generated new variables with
y total y25_29 y18_24 median_age
2010 4785437 311118 479755 37.9
2011 4799069 310059 481645 38.1
2012 4815588 309846 485324 38.2
2013 4830081 311691 486637 38.4
2014 4841799 316637 480552 38.6
2015 4852347 324247 471498 38.7
2016 4863525 332820 461617 38.9
2017 4874486 338461 454873 39
2018 4887681 340112 452369 39.2
2019 4903185 338138 450224 39.4
Code:
g Total = total
etc, see below:
Total share18_29 year25_29 year18_14
1 9 3 6
2 5 2 8
3 3.333333 1 9
4 3.5 4 10
5 2.4 5 7
6 1.833333 6 5
7 1.571429 7 4
8 1.5 9 3
9 1.333333 10 2
10 .9 8 1
I than exported the data to an xls file and back into stata and finally stata used the actual values to generate the share of people between 18 and 29.
Now here's my question: Why didn't it work before?

Best regards
Philipp

PS: sorry for the spelling mistake in the thread name