Code:
sysuse auto, clear gen d = (rep78 > 2) & !missing(rep78)
Specialized on Data processing, Data management Implementation plan, Data Collection tools - electronic and paper base, Data cleaning specifications, Data extraction, Data transformation, Data load, Analytical Datasets, and Data analysis. BJ Data Tech Solutions teaches on design and developing Electronic Data Collection Tools using CSPro, and STATA commands for data manipulation. Setting up Data Management systems using modern data technologies such as Relational Databases, C#, PHP and Android.
sysuse auto, clear gen d = (rep78 > 2) & !missing(rep78)
clear input byte(ye ma) int co byte org float(qu share) 70 1 411 2 1100 .004219555 70 1 241 6 544 .0020867616 70 1 499 7 1880 .007211603 70 1 196 1 8600 .03298925 70 1 413 2 1000 .003835959 70 1 488 2 5400 .02071418 70 1 212 1 7150 .027427107 70 1 134 2 6660 .02554749 70 1 64 3 7800 .02992048 70 1 410 2 2100 .008055514 70 1 500 7 690 .002646812 70 1 400 3 800 .003068767 70 1 439 2 2500 .009589897 70 1 435 3 7200 .027618906 70 1 429 3 4300 .016494624 70 1 36 1 6700 .025700925 70 1 458 3 800 .003068767 70 1 481 2 380 .0014576644 70 1 434 3 1100 .004219555 70 1 217 7 7350 .0281943 70 1 530 7 350 .0013425857 70 1 437 2 7600 .02915329 70 1 269 4 9350 .035866216 70 1 408 2 1350 .005178545 70 1 15 2 2700 .01035709 70 1 412 2 2200 .00843911 70 1 172 2 11000 .04219555 70 1 447 4 560 .002148137 70 1 478 2 150 .00057539385 70 1 455 3 220 .000843911 70 1 402 3 1200 .0046031508 70 1 431 3 2300 .008822706 70 1 430 3 3300 .012658665 70 1 417 1 3700 .01419305 70 1 419 1 1300 .004986747 70 1 26 1 3500 .013425857 70 1 497 1 6350 .02435834 70 1 491 1 6000 .023015754 70 1 174 2 1500 .005753939 70 1 418 1 4650 .01783721 70 1 422 8 7475 .028673794 70 1 521 1 14100 .05408702 70 1 503 7 250 .0009589898 70 1 407 2 2200 .00843911 70 1 406 2 3000 .011507877 70 1 214 1 4450 .017070018 70 1 535 6 2000 .007671918 70 1 524 1 3800 .014576645 70 1 213 1 8000 .030687673 70 1 544 2 5200 .019946987 end
tab org ma, summarize(share)
sum share if ma==1 & ye==71
webuse auto,clear replace headroom=. if mpg==17 replace weight=. if mpg==22|mpg==17 //I did the above manipulation so that some observations have only one nonmissing value in the varlist to be considered below //so that you cannot simply apply egen rowmean to fulfil my task keep rep78 headroom weight rename rep78 var1 rename headroom var2 rename weight var3 //how to generate a variable that equals the mean of the first two nonmissing variables in the varlist (var1, var2, var3) //and record which two of the three variables in my list have been used to generate the new variable?
* clear input str5 var1 str27 var2 "one" "the diameter of the earth" "two" "the diameter of venus" "three" "the diameter of jupiter" "four" "the population of paris" "five" "the surface area of england" "six" "the population of phoenix" end
matrix R_c = (0,0,1,1,1) gen r=1
reg lcost loutput lplabor lcapital lpfuel constraint 3 _b[lpfuel]=_b[lplabor]=_b[lcapital]=1 cnsreg lcost loutput lplabor lcapital lpfuel, constraints(3)
summarize
tabulate
codebook
describe
putdocx table table1=etable
putdocx text (" ‘r(mean)’ ")
year | Agric | Food | Drug | Books |
2000 | 1.12 | 1.45 | 0.97 | … |
2001 | 1.05 | 1.6 | 0.88 | … |
2002 | 1.18 | 1.34 | 0.92 | … |
year | Industry | Ind_Beta |
2000 | Agric | 1.12 |
2000 | Food | 1.45 |
2000 | Drug | 0.97 |
2000 | … | … |
2001 | Agric | 1.05 |
2001 | Food | 1.6 |
2001 | Drug | 0.88 |
2001 | … | … |
2002 | Agric | 1.18 |
2002 | Food | 1.34 |
2002 | Drug | 0.92 |
2002 | … | … |
* Example generated by -dataex-. For more info, type help dataex clear input int year float(agric food beer smoke toys fun books) 2000 .3452645 .13540165 .004693561 .10387945 .5594783 .7765604 .672514 2001 .4666844 .19018325 .22386266 .13462715 .7232649 1.2980112 .6057138 2002 .4180116 .4688401 .4606416 .3165837 .8264946 1.0237317 .7255396 2003 .6058208 .5994597 .54949224 .58115196 .8094561 1.174974 .8105838 2004 .645611 .618094 .5450272 .6523659 1.0529572 1.0226463 .6682123 2005 .7191871 .6432664 .6079998 .8309416 1.2295903 1.1020511 .7842661 2006 .7900746 .5786355 .4802569 .4810273 .9801628 .9165996 .7079894 2007 1.3577225 .7155325 .5886528 .634958 .7687722 1.0139668 .8080173 2008 1.1235923 .6186133 .5526155 .6556639 .8520126 1.213102 1.132914 2009 .6970165 .52631867 .4582001 .3303039 1.0007415 1.5126996 1.307686 2010 .7568682 .5700232 .5300202 .6517677 1.0587844 1.4952796 1.1704426 2011 1.0809941 .6031252 .5268776 .5393996 .980441 1.2700168 1.1069671 2012 1.0136213 .572837 .52827054 .5611398 1.0247171 1.2806007 .9967803 2013 .9104237 .8755165 .7196253 .7702268 .9460964 1.228237 1.176336 2014 .7878072 .7916082 .5841157 .6283697 1.0399202 1.299612 1.1335369 2015 .9148453 .7809891 .7545701 .7404549 1.0749298 1.199249 1.0286957 end
* Example generated by -dataex-. For more info, type help dataex clear input long pais float(year ln_co2pc_gr ln_gdppc_gr co2pc_gr gdppc_gr res_share_ch ei_ch) 1 1970 . . . . . . 1 1971 .04318523 . .04413044 . -.6838717 . 1 1972 -.003316879 . -.003311346 . -.5843963 . 1 1973 .035467148 . .036103528 . -.19065896 . 1 1974 -.01744461 . -.017293148 . 1.1816183 . 1 1975 -.04150105 . -.04065147 . -1.1635613 . 1 1976 .02756405 . .027947137 . -.4502255 . 1 1977 .027318 . .02769508 . .4519265 . 1 1978 -.01889515 . -.01871785 . .7232267 . 1 1979 .03856087 . .03931371 . -.03159031 . 1 1980 -.033974648 . -.03340414 . 1.6892276 . 1 1981 -.03340912 . -.032857135 . .3562208 . 1 1982 -.029852867 . -.02941179 . .22335 . 1 1983 .010718346 . .010776284 . .55891395 . 1 1984 -.025982857 . -.02564822 . .3025955 . 1 1985 -.09177828 . -.08769248 . .2845615 . 1 1986 .06215334 . .06412572 . -.57471985 . 1 1987 .035816193 . .0364652 . -.04727695 . 1 1988 .01995754 . .020158285 . -2.0891473 . 1 1989 -.051548 . -.05024241 . -.8556552 . 1 1990 -.08002138 . -.07690334 . 2.5997005 . 1 1991 .04825544 .07338333 .04943905 .07614343 -.7621235 -.003763424 1 1992 .014944077 .06285858 .015055898 .064876065 .8977495 -.004395153 1 1993 .020612717 .06581497 .020826785 .06802921 .9866562 -.005773365 1 1994 .02478409 .04406929 .0250941 .04505472 .05130513 .0004600968 1 1995 -.012306213 -.04115677 -.012230685 -.04032156 .1040608 .003823304 1 1996 .04091835 .04185772 .04176683 .04274599 -.889446 -.0021086514 1 1997 .0079956055 .06639385 .008027056 .06864754 .5504242 -.0032310374 1 1998 .014033318 .02645588 .014132484 .02680954 .14474016 -.0015993596 1 1999 .029364586 -.04557419 .02980039 -.04455157 -1.4123623 .004682073 1 2000 -.013619423 -.018927574 -.013527458 -.018749123 -.7077209 .006655703 1 2001 -.04242325 -.05601025 -.04153631 -.05447092 1.7975198 -.0001920025 1 2002 -.064777374 -.12618446 -.06272339 -.11854777 .4461319 .0078657 1 2003 .05957603 .07396126 .0613862 .07676546 -.9268353 -.00195185 1 2004 .07559109 .0758953 .07852178 .07884938 -1.3884256 .00006687366 1 2005 .02943516 .074453354 .029872544 .07729475 .53251714 -.005813921 1 2006 .04256248 .06724262 .04348141 .06955548 .10701164 -.0033557636 1 2007 .08056164 .07625961 .08389506 .07924238 -1.0392638 -.0004027938 1 2008 .02333355 .02984524 .02360851 .03029477 .4650531 -.0015919253 1 2009 -.07792091 -.07100487 -.07496273 -.06854227 1.7649453 -.0008191558 1 2010 .07104397 .0862999 .07362857 .09013356 .3953756 -.003054402 1 2011 .036629677 .04797363 .03730834 .049143 .19075124 -.001405331 1 2012 .005539894 -.02078247 .0055553 -.020567933 -.5361876 .0016440516 1 2013 .017653465 .013266563 .017810239 .01335466 .006848871 .0002165544 1 2014 -.02623844 -.035855293 -.025896933 -.035220277 .9186995 .0021337224 1 2015 .01380539 .016727448 .013901046 .016867941 -1.0696038 -.001246282 1 2016 -.014710426 -.031025887 -.014602168 -.03054932 .5231693 .001930914 1 2017 -.024267197 .01653099 -.02397574 .016668873 1.1013072 -.0032586295 1 2018 -.04940796 -.034734726 -.04820735 -.03413885 -.1671047 .0007113228 1 2019 -.03939629 -.031279564 -.03863 -.03079537 -.0826373 .00057273713 1 2020 . . . . . . 2 1970 . . . . . . 2 1971 .03735685 . .03806343 . -3.583941 . 2 1972 .006715775 . .006738317 . -3.595976 . 2 1973 .0723815 . .07506522 . 1.0047908 . 2 1974 -.013946533 . -.013849764 . -2.443425 . 2 1975 .06486988 . .067020305 . -5.076143 . 2 1976 .06060696 . .06248108 . 1.480327 . 2 1977 .15053034 . .1624507 . -.9558575 . 2 1978 .05724525 . .05891533 . -5.38981 . 2 1979 .2042713 . .226631 . 1.2600955 . 2 1980 .064723015 . .066863455 . 2.294343 . 2 1981 .0004091263 . .0004090958 . -4.1512866 . 2 1982 -.010876656 . -.010817155 . -1.286386 . 2 1983 -.08180618 . -.07854988 . -.2205604 . 2 1984 .02359295 . .02387344 . .52316314 . 2 1985 -.05776501 . -.05612823 . -.6478212 . 2 1986 .281785 . .3254935 . -.4750064 . 2 1987 .062625885 . .064629 . -5.436717 . 2 1988 .008115768 . .008148801 . .7065676 . 2 1989 .05866051 . .06041504 . -1.0042635 . 2 1990 -.02052593 . -.02031715 . .9601043 . 2 1991 -.0022001266 -.0434866 -.002197118 -.0425546 -.832518 .01618729 2 1992 -.12391949 -.06234837 -.11654889 -.06044444 -1.431724 -.023318866 2 1993 -.013767242 .0041484833 -.01367371 .0041567744 -1.408625 .0024125425 2 1994 .1101904 .016054153 .116491 .016183637 1.988639 .008190635 2 1995 .034041405 .015937805 .03462734 .0160664 -1.8642867 .006239843 2 1996 .0448246 .034890175 .04584408 .035505243 .2397784 .0004650287 2 1997 .12469387 .04205894 .1328022 .04295658 -.6353271 .0079945 2 1998 -.02123642 .032331467 -.021012744 .032859545 .59386986 -.00912828 2 1999 .05735397 -.000790596 .05903048 -.0007899858 -2.49613 .004564094 2 2000 .04701233 .03958511 .04813543 .04037887 2.706013 .004879483 2 2001 -.04536247 -.027560234 -.04434931 -.02718382 -1.0512298 -.00504469 2 2002 -.015072823 .0044546127 -.014959444 .004464366 .05328191 -.002887168 2 2003 .0005598068 .018220901 .00055978925 .018387806 -.10914221 -.002539354 2 2004 .012296677 .010541916 .012372726 .010597872 -.2341628 -.00010549345 2 2005 .017718315 .035025597 .017876115 .035645753 .7751106 -.003184567 2 2006 .008773804 .0531826 .008812081 .05462261 -1.2377497 -.00716155 2 2007 .010412216 .01738453 .010466738 .017535998 .3962357 -.0003483627 2 2008 .15820885 .002524376 .1714113 .002528249 -.927561 .01863219 2 2009 -.035902023 -.05624008 -.03526547 -.05468835 .4229553 .003304608 2 2010 -.07738018 -.02677727 -.07446237 -.02642146 -.8142483 -.00818127 2 2011 .0507679 -.009784698 .05207909 -.0097374 -.3567042 .007837007 2 2012 -.06547451 -.007086754 -.06337695 -.00706133 -.08397305 -.0083234655 2 2013 .010436058 -.016260147 .010490787 -.016129091 -1.083137 .0025542805 2 2014 -.09462738 -.003108978 -.09028804 -.003103939 .20679207 -.01407241 2 2015 -.010979652 .022444725 -.010919874 .022698896 -1.1899234 -.004809058 2 2016 -.06432438 .022831917 -.06229942 .023094524 .5234437 -.009212221 2 2017 .026329994 .00321579 .026679393 .00322063 .5948993 .004054799 2 2018 .01234913 -.007247925 .012426493 -.007221923 .7516962 .000632762 end label values pais pais label def pais 1 "Argentina", modify label def pais 2 "Barbados", modify
xtunitroot ips ln_co2pc_gr ln_gdppc_gr if year > 1990 & year <2020
xtunitroot ips ln_co2pc_gr if year > 1990 & year <2020
* Example generated by -dataex-. For more info, type help dataex clear input int(gvkey fyear) byte(cvcie1 cvcie0) 1001 2011 55 . 1001 2011 . 73 1001 2011 . 73 1001 2011 . 73 1001 2011 . 73 1001 2011 . 73 1001 2011 55 . 1001 2011 55 . 1001 2011 . 73 1001 2012 64 . 1001 2012 64 . 1001 2012 . 23 1001 2012 . 23 1002 2011 12 . 1002 2011 12 . 1002 2011 . 15 1002 2011 . 15 end
* Example generated by -dataex-. For more info, type help dataex clear input int(A B) str9 C float(ID1 ID2) 1 2010 "艾一" 2 1 1 2011 "张三" 1 2 1 2012 "张三" 1 2 2 2010 "李四" 3 3 2 2011 "李四" 3 3 3 2012 "车八" 6 4 3 2013 "王五" 5 5 3 2014 "李白" 4 6 end
egen ID1=group(A C)
* Example generated by -dataex-. To install: ssc install dataex clear input int year float index str87 country float ca 1980 15 "Algeria" 61248.55 1981 15 "Algeria" 63086 1982 15 "Algeria" 67123.51 1983 15 "Algeria" 70748.18 1984 15 "Algeria" 74710.08 1985 15 "Algeria" 77474.35 1986 15 "Algeria" 77784.24 1987 15 "Algeria" 77239.76 1988 15 "Algeria" 76467.36 1989 15 "Algeria" 79831.92 1980 39 "Benin" 1860.74 1981 39 "Benin" 1965.387 1982 39 "Benin" 2177.307 1983 39 "Benin" 2082.683 1984 39 "Benin" 2247.842 1985 39 "Benin" 2417.076 1986 39 "Benin" 2469.006 1987 39 "Benin" 2431.971 1988 39 "Benin" 2505.768 1989 39 "Benin" 2488.038 1980 1 "Botswana" 1516.087 1981 1 "Botswana" 1694.112 1982 1 "Botswana" 1837.036 1983 1 "Botswana" 2055.612 1984 1 "Botswana" 2335.366 1985 1 "Botswana" 2550.895 1986 1 "Botswana" 2738.062 1987 1 "Botswana" 2963.26 1988 1 "Botswana" 3325.464 1989 1 "Botswana" 4431.94 1980 14 "Burkina Faso" 2192.041 1981 14 "Burkina Faso" 2288.216 1982 14 "Burkina Faso" 2339.263 1983 14 "Burkina Faso" 2311.912 1984 14 "Burkina Faso" 2349.373 1985 14 "Burkina Faso" 2656.291 1986 14 "Burkina Faso" 2867.462 1987 14 "Burkina Faso" 2860.642 1988 14 "Burkina Faso" 3026.523 1989 14 "Burkina Faso" 3091.73 1980 30 "Burundi" 1344.64 1981 30 "Burundi" 1491.376 1982 30 "Burundi" 1484.951 1983 30 "Burundi" 1531.115 1984 30 "Burundi" 1529.591 1985 30 "Burundi" 1708.338 1986 30 "Burundi" 1773.586 1987 30 "Burundi" 1846.2 1988 30 "Burundi" 1936.524 1989 30 "Burundi" 1965.25 1980 2 "Cabo Verde" 278.052 1981 2 "Cabo Verde" 301.547 1982 2 "Cabo Verde" 310.067 1983 2 "Cabo Verde" 339.59 1984 2 "Cabo Verde" 352.435 1985 2 "Cabo Verde" 382.893 1986 2 "Cabo Verde" 393.889 1987 2 "Cabo Verde" 410.86 1988 2 "Cabo Verde" 435.498 1989 2 "Cabo Verde" 460.317 1980 3 "Cameroon" 12794.186 1981 3 "Cameroon" 13726.994 1982 3 "Cameroon" 14749.424 1983 3 "Cameroon" 15988.812 1984 3 "Cameroon" 17275.252 1985 3 "Cameroon" 17681.533 1986 3 "Cameroon" 16752.086 1987 3 "Cameroon" 15813.303 1988 3 "Cameroon" 15216.575 1989 3 "Cameroon" 14737.848 1980 35 "Central African Republic" 1490.16 1981 35 "Central African Republic" 1513.225 1982 35 "Central African Republic" 1540.405 1983 35 "Central African Republic" 1446.484 1984 35 "Central African Republic" 1550.996 1985 35 "Central African Republic" 1602.746 1986 35 "Central African Republic" 1660.092 1987 35 "Central African Republic" 1578.233 1988 35 "Central African Republic" 1611.128 1989 35 "Central African Republic" 1651.01 1980 31 "Comoros" 421.845 1981 31 "Comoros" 438.149 1982 31 "Comoros" 466.119 1983 31 "Comoros" 488.591 1984 31 "Comoros" 508.673 1985 31 "Comoros" 518.847 1986 31 "Comoros" 529.224 1987 31 "Comoros" 537.892 1988 31 "Comoros" 552.348 1989 31 "Comoros" 543.308 1980 16 "Congo" 3243.096 1981 16 "Congo" 3931.224 1982 16 "Congo" 4857.743 1983 16 "Congo" 5130.247 1984 16 "Congo" 5500.578 1985 16 "Congo" 5437.178 1986 16 "Congo" 5062.998 1987 16 "Congo" 5072.587 1988 16 "Congo" 5162.182 1989 16 "Congo" 5253.278 end
Year | Market | Brand | Sales | Market Share |
2000 | 1 | 1 | 56 | A |
2001 | 1 | 1 | 34 | B |
2002 | 1 | 1 | 45 | |
2001 | 1 | 2 | 54 | |
2002 | 1 | 2 | 46 | |
2000 | 1 | 3 | 25 | |
2001 | 1 | 3 | 43 | |
2002 | 1 | 3 | 41 | |
2000 | 2 | 1 | 47 | C |
2001 | 2 | 1 | 65 | |
2002 | 2 | 1 | 62 | |
2001 | 2 | 2 | 21 | |
2002 | 2 | 2 | 43 | |
2000 | 2 | 3 | 43 |
Investor_name | Investor_group |
Blue Ocean | Blue Ocean Partners |
Blue Ocean Partners | Blue Ocean Partners |
Blue Ocean Partners LLC | Blue Ocean Partners |
Breakthrough Energy | Breakthrough Energy |
Deutsche Bank | Deutsche Bank |
Goldman | Goldman Sachs |
Goldman Sachs | Goldman Sachs |
Goldman Sachs, Inc | Goldman Sachs |
Google Ventures | |
J.P. Morgan | JP Morgan |
JP Morgan | JP Morgan |
JP Morgan Chase | JP Morgan |
Kleiner Perkins | Kleiner Perkins |
Kleiner Perkins Caufield & Byers | Kleiner Perkins |
Biomet Orthopedics, LLC | Biomet |
Biomet Spine, LLC | Biomet |
Biomet Trauma, LLC | Biomet |
Biomet Sports Medicine, LLC | Biomet |
BIomet 3i, LLC | Biomet |
Biomet Microfixation, LLC | Biomet |
Biomet Biologics, LLC | Biomet |
Davol Inc. | C. R. Bard |
Bard Peripheral Vascular, Inc. | C. R. Bard |
C. R. Bard, Inc. & Subsidiaries | C. R. Bard |
Bard Access Systems, Inc. | C. R. Bard |
DePuy Synthes Products LLC | DePuy |
DePuy Mitek LLC | DePuy |
DePuy Orthopaedics Inc. | DePuy |
Synthes USA Products LLC | DePuy |
DePuy Spine, LLC | DePuy |
ID | Country | Domain | Condition | Total |
1 | 1 | 1 | 2 | 2 |
1 | 1 | 2 | 2 | 2 |
1 | 1 | 3 | 2 | 1.833333254 |
2 | 1 | 1 | 1 | 2.416666746 |
2 | 1 | 2 | 1 | 1.916666627 |
2 | 1 | 3 | 1 | 3.416666746 |
3 | 1 | 1 | 2 | 2.916666508 |
3 | 1 | 2 | 1 | 2.833333254 |
3 | 1 | 3 | 2 | 2.75 |
4 | 2 | 1 | 2 | 1.5 |
4 | 2 | 2 | 2 | 1.666666746 |
4 | 2 | 3 | 2 | 1.166666627 |
5 | 2 | 1 | 1 | 2.416666746 |
5 | 2 | 2 | 2 | 2.75 |
5 | 2 | 3 | 2 | 2.583333254 |
6 | 2 | 1 | 1 | 2.333333492 |
6 | 2 | 2 | 2 | 3.5 |
6 | 2 | 3 | 1 | 2 |
local yvars 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 /// 2011 2013 2015 2017 foreach i in 1 2 3 4 5 6 { local y: word `i' of `yvars' //job number recode job`i'_sched`y' (-6/-1=.) (2/6 8 = 0)(1 7 9 = 1),gen(job`i'_schedx`y') }
(8734 differences between job1_sched1997 and job1_schedx1997) (8742 differences between job2_sched1998 and job2_schedx1998) (8865 differences between job3_sched1999 and job3_schedx1999) (8913 differences between job4_sched2000 and job4_schedx2000) (8960 differences between job5_sched2001 and job5_schedx2001) (8979 differences between job6_sched2002 and job6_schedx2002)
. quietly mlogit gender_n c.year##i.position_department_n, rrr vce(cluster person) . quietly margins i.position_department_n, at(year=(1(1)7)) . . **WITHOUT ADD PLOT . . marginsplot, bydimension(position_department_n) legend(pos(3)) recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ytitle("Propor > tion") plotd(,label( "F" "M" "U")) Variables that uniquely identify margins: year position_department_n _outcome Array . . **WITH ADDPLOT . . marginsplot, bydimension(position_department_n) legend(pos(3)) recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ytitle("Propor > tion") plotd(,label( "F" "M" "U")) addplot((scatter prop year if gender_n==4, msymbol(circle) mcolor(black) msize(vsmall)) (scatter prop year if gender_ > n==5, msymbol(circle) mcolor(black) msize(vsmall)) (scatter prop year if gender_n==6, msymbol(circle) mcolor(black) msize(vsmall))) Variables that uniquely identify margins: year position_department_n _outcome Graph family bygraph_g does not support addplot. r(198);
clear all webuse highschool, clear svyset [pweight=sampwgt] * making a fake year variable set seed 12345 generate rannum = uniform() sort rannum generate year = . lab var year "grad year" drop rannum replace year = 2009 in 1/999 replace year = 2010 in 1000/1999 replace year = 2011 in 2000/2999 replace year = 2012 in 3000/4071 * making a fake outcome variable set seed 54321 generate rannum = uniform() sort rannum generate happy = . lab var happy "happiness index" drop rannum replace happy = 1 in 1/700 replace happy = 2 in 701/2200 replace happy = 3 in 2201/4071 label define happy 1 "unhappy" 2 "neutral" 3 "happy" label values happy happy codebook, compact
*attempt 1 (using svy:mean with subpop for the if statement restricting year)
svy, subpop(if year==2009): mean happy, over(race) coeflegend
(running mean on estimation sample) Survey: Mean estimation Number of strata = 1 Number of obs = 4,071 Number of PSUs = 4,071 Population size = 8,000,000 Subpop. no. obs = 999 Subpop. size = 2,016,463 Design df = 4,070 ------------------------------------------------------------------------------ | Mean Legend -------------+---------------------------------------------------------------- c.happy@race | White | 2.325196 _b[c.happy@1bn.race] Black | 2.207406 _b[c.happy@2.race] Other | 2.30351 _b[c.happy@3.race] ------------------------------------------------------------------------------
*attempt 2 (using weights with arithmetic and stock Stata)
sort race year
by race year: gen meanHappy = sum(happy* sampwgt) / sum(sampwgt)
by race year: replace meanHappy=meanHappy[_N]
tabstat meanHappy if year==2009, statistics(mean) by(race) columns(statistics)
Summary for variables: meanHappy by categories of: race (1=white, 2=black, 3=other) race | mean -------+---------- White | 2.325196 Black | 2.207406 Other | 2.303509 -------+---------- Total | 2.312006 ------------------
* a tabulation that sorts these means in descending order
White | 2.325196
Other | 2.303509
Black | 2.207406
__method __or_ __lci_or_ __uci_or_ A .6492 .258189 1.63237 B .682846 .133547 3.49148 C .6492 .10206 4.12953 D .586633 .299436 1.14929 E .594977 .303478 1.16647 F .342782 .134567 .873165 G .119268 .012092 1.17643 H .342782 .016632 7.06464 I .660587 .209265 2.08528 J .660587 .209265 2.08528 K .660587 .209265 2.08528 L .778194 .325669 1.85951 M .711595 .193472 2.61727 N .778194 .185898 3.25763 O .790423 .437463 1.42816 P .018483 .001191 .286725 Q .587435 .298901 1.15449 R .783607 .432965 1.41822 S .601916 .306494 1.18209 T .165793 .012218 2.24971 U .280154 .017255 4.54869 V .790423 .437463 1.42816 W .751405 .499381 1.13062 X .757768 .477562 1.20238 Y .880356 .200964 3.85654
exlogistic r id group, binomial(n) group(id)
Exact logistic regression Number of obs = 576 Group variable: __id Number of groups = 8 Binomial variable: __n Obs per group: min = 26 avg = 72.0 max = 197 Model score = 2.41637 Pr >= score = 0.1258 --------------------------------------------------------------------------- __r | Odds Ratio Suff. 2*Pr(Suff.) [95% Conf. Interval] -------------+------------------------------------------------------------- __group | .5874346 23 0.1664 .279409 1.216778 ---------------------------------------------------------------------------
gen se = _se[__group]
no variables defined r(111);
predict probabilities
webuse auto.dta, replace gen dummy=0 replace dummy=1 if price>9500 rename logit dummy logit dummy mpg trunk length gen probabilities2=1/(1+exp(-(_b[mpg]*mpg+_b[trunk]*trunk+_b[length]*length+_b[_cons]*_cons)))
logit dummy mpg trunk length matrix bmatrix=e(b) mat accum m = mpg trunk length matrix xb=bmatrix*m gen probabilities=1/(1+exp(-(xb)))
dictionary { _column(1) int ANNO %4f "ANNO" _column(5) int TRIM %1f "TRIM" _column(6) int REG %2f "REG" _column(8) int numcff %2f "SG4" (...) _column(587) int STDFAM %6f "STDFAM" _column(593) int STDIND %6f "STDIND" _column(599) int NN2 %1f "NN2" _column(600) int RPN2 %1f "RPN2" _column(601) int TF %2f "TF" _column(603) int TN2 %1f "TN2" _column(604) int F0_14 %1f "F0_14" _column(605) int CP0_7 %1f "CP0_7" _column(606) int CITTAD %1f "CITTAD" _column(607) int WAVQUA %1f "WAVQUA" _column(608) int nasita %1f "SG13" _column(609) int citita %1f "SG16" _column(610) int annres %3f "SG18" _column(613) int NASSES %3f "NASSES" _column(616) int CITSES %3f "CITSES" _column(619) int RAPSES %3f "RAPSES" }
clear infile using "$PathDict/2005_Q2_dict.dct", using("$Path05Q2/sta_2005_2.txt")
generate wanted = . mata: st_store(., "wanted", rdiscrete(2100, 1, ("0.5", "0.2", "0.3")))
generate wanted = . mata: st_store(., "wanted", rdiscrete(2100, 1, ("prob_1", "prob_2", "prob_3")))
forvalues i = 1(1)2100 { local prob_1_local = prob_1[`i'] local prob_2_local = prob_2[`i'] local prob_3_local = prob_3[`i'] display `prob_1_local' display `prob_2_local' display `prob_3_local' mata: st_store(., "wanted", rdiscrete(1, 1, (`prob_1_local', `prob_2_local', `prob_3_local'))) }
* Example generated by -dataex-. To install: ssc install dataex clear input long gid int(country_code year) long actor_id 62356 . 1997 . 62357 . 1997 . 79600 710 2012 2664 79601 710 2015 2664 79601 710 2015 2664 79601 710 1999 2794 79601 710 2013 2664 79601 710 2013 2664 79601 710 1999 2794 79601 710 2013 2664 80317 710 2015 2794 80317 710 2012 2664 80317 710 2017 2664 80317 710 2015 2664 80317 710 2015 2664 80317 710 2012 2535 80317 710 2002 2794 80317 710 2008 2664 80317 710 2015 2664 80317 710 2013 2794 80317 710 2009 2794 80317 710 2014 2794 80317 710 2009 2794 80317 710 2008 2664 80317 710 2017 2794 80317 710 2015 2794 80317 710 2015 2794 80317 710 2015 2794 80317 710 2008 2794 80317 710 2012 2664 80317 710 2015 2774 80317 710 2010 2794 80317 710 2017 2664 80317 710 2015 2664 80317 710 2014 2794 80317 710 2016 2664 80317 710 2016 2664 80317 710 2015 2794 80317 710 2014 2664 80317 710 2015 2794 80317 710 2016 2664 80317 710 2009 2794 80317 710 2012 2664 80317 710 2017 2794 80317 710 1999 2664 80317 710 2013 2794 80317 710 2009 2664 80317 710 2015 2794 80317 710 2012 2664 80317 710 2017 2664 80317 710 2017 2794 80317 710 2016 3181 80317 710 2016 2664 80317 710 2009 2794 80317 710 2012 2535 80317 710 2012 2794 80317 710 2010 2664 80317 710 2012 2664 80317 710 2015 2794 80317 710 2010 2664 80317 710 2015 2664 80317 710 2012 2794 80317 710 2017 2794 80317 710 2015 2664 80317 710 2012 2535 80317 710 2017 2794 80317 710 2012 2794 80317 710 2014 2794 80317 710 2015 2794 80317 710 2017 2794 80317 710 2014 2794 80317 710 2016 2664 80317 710 2015 2794 80317 710 2008 2794 80317 710 2017 2664 80317 710 2015 2794 80317 710 2015 2794 80317 710 2006 2664 80317 710 2012 2664 80317 710 2017 2664 80317 710 2012 2664 80317 710 2017 2664 80317 710 2009 2794 80317 710 2017 2794 80317 710 2001 2794 80317 710 2015 2794 80317 710 2017 2794 80317 710 2012 2664 80317 710 2017 2664 80317 710 2017 2794 80317 710 2017 2664 80317 710 2009 2794 80317 710 2013 2188 80317 710 2014 2664 80317 710 2009 2794 80317 710 2015 2794 80317 710 2015 2664 80317 710 2017 2664 80317 710 2013 2664 80317 710 2012 2664 end
bysort gid year actor_id: gen nactors = _n keep if nactors == 1 egen nactors2 = count(nactors), by(year gid)
Table: Hausman Test | |||
Ho: difference in coefficients not systematic | |||
chi2(6) = (b-B)'[(V_b-V_B) ^(-1)](b-B) = 251.86 Prob>chi2 = 0.0000 (V_b-V_B is not positive definite)
|
Table: Wald test for heteroskedasticity |
H0: sigma(i)^2 = sigma^2 for all i chi2 (252) = 2.8e+38 Prob>chi2 = 0.0000 |
Table:Wooldridge test for autocorrelation |
H0: no first-order autocorrelation F (1, 244) = 873.172 Prob > F = 0.0000 |
xtgls
xtreg
cluster
* Example generated by -dataex-. For more info, type help dataex clear input str6 date float newdate "202101" 732 "202102" 733 end format %tm newdate
. svy: graph bar nuclear if nuclear!=6 graph is not supported by svy with vce(linearized); see help svy estimation for a list of Stata estimation commands that are supported by svy r(322);
#delimit ; svyset [pweight=_one], rake(i.gender2 i.age1 i.region1 i.race3 i.latino i.educ1, totals(_cons=25127 1.gender2=12236 2.gender2=12891 1.age1=7568 2.age1=8305 3.age1=9254 1.region1=5260 2.region1=4435 3.region1=9499 4.region1=5933 1.race3=18242 2.race3=3191 3.race3=3694 1.latino=20604 2.latino=4523 1.educ1=9944 2.educ1=7748 3.educ1=7435 )); #delimit cr
#delimit ; svycal rake i.gender2 i.age1 i.region1 i.race3 i.latino i.educ1 [pw=_one], gen(rake_wt) totals(_cons=25127 1.gender2=12236 2.gender2=12891 1.age1=7568 2.age1=8305 3.age1=9254 1.region1=5260 2.region1=4435 3.region1=9499 4.region1=5933 1.race3=18242 2.race3=3191 3.race3=3694 1.latino=20604 2.latino=4523 1.educ1=9944 2.educ1=7748 3.educ1=7435 ) ; #delimit cr
. svy: mean nuclear if nuclear!=6 (running mean on estimation sample) Survey: Mean estimation Number of strata = 1 Number of obs = 2,836 Number of PSUs = 2,836 Population size = 25,127 Calibration : rake Design df = 2,835 -------------------------------------------------------------- | Linearized | Mean Std. Err. [95% Conf. Interval] -------------+------------------------------------------------ nuclear | 3.087027 .0283936 3.031353 3.142701 --------------------------------------------------------------
graph bar nuclear if nuclear!=6 [pw = rake_wt]