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* }
Code:
g share18_29 = (y18_24 + y25_29)/total
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
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 |
Now here's my question: Why didn't it work before?
Best regards
Philipp
PS: sorry for the spelling mistake in the thread name
0 Response to stata doesn't recognises the values of variables
Post a Comment