Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: easier way?


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: easier way?
Date   Wed, 4 Jul 2007 14:59:59 -0400

Dear Mr. Kruk:

You have committed mistakes that many inexperienced researchers make. First you made variable names that are much too long. Such long names take much time to type, and it is easy to make mistakes when typing them. Experienced researchers keep names to under 10 characters. To make results understandable, they create descriptive variable labels.

Second, you claim to need totals for "later." Like Professor Cross, I cannot see why you need these totals. I would guess that you simply need to create category variables. If you really need totals then you can use the -contract- command or a -bysort: gen- combination of commands.

Third, you are estimating totals that will be descriptive of your sample, but you will be useless if you need weighted estimates. So, you will have to learn the survey commands in Stata. These will operate on the categories you create.

So, suggested commands to start you off:

/ ************************************************************************ ***/
/* Create labour force category variable */
label define lf_cat 1 "Employed" 2 "Unemployed" 3 "<14" 4 "Inactive"

gen lf_cat=1 if popcoac==2
replace lf_cat =2 if inlist(popcoac,3,4,5)
replace lf_cat =3 if popcoac==1
replace lf_cat =4 if inrange(popcoac,6,11)

label var lf_cat "Labour Force Category"

label values lf_cat lf_cat

/* To see totals */
table sex chief lf_cat, missing
save d1

/* To create totals by category */
bysort sex chief lf_cat: gen count=_N
bysort sex chief lf_cat: keep if _n==_N
keep sex chief lf_cat count
list sex chief lf_cat count
save d2, replace

/* Use -contract- to do the same thing */
use d1,clear
contract sex chief lf_cat, zero //Adds zero cells
rename _freq count
list // Should be the same as the previous list, except that zero cells will be included

save d3, replace
/*******************************************************************/

-Steven Samuels



On Jul 4, 2007, at 12:45 PM, Sebastian Kruk wrote:


What is "it" that you want to do?
I have a household survey. I want to obtain data on the labour force
which is subcategorized by employed (when pobpcoac equals 2) and
unemployed (when pobpcoac equals 3 or 4 or 5), <14 years old (when
pobpcoac equals 1) and inactive population (when pobpcoac is between 6
and 11) by sex and chief or not of the house.

If you want just to get totals of variables, there is a command called -total-.
I want to get totals of variables under some restrictions.

Otherwise, there is little point in filling variables with constants,
unless you really >need those variables later.

If you really do, look at -foreach- as a way of looping over
variables. -search >foreach- will indicate sources of tutorials.

I'm just beginning to learn Stata.

Your variable name structure makes looping a little difficult.
I don't care about names, I just want to obtaing employed, unemployed,
and inactive population.

Putting "indice" inside each variable name is awkward.
Do you know spanish?

Nick
[email protected]
Sebastian Kruk

Are there a easier way of do it?

egen desocupados_indice = anycount (pobpcoac), values(3 4 5)

egen byte desocupados_indice_man = anycount(pobpcoac) if
e1==1, values(3 4 5)

egen byte desocupados_indice_man_jefe = anycount(pobpcoac) if e1==1 &
e3==1, values(3 4 5)

egen byte desocupados_indice_man_no_jefe = anycount(pobpcoac) if e1==1
& e3!=1, values(3 4 5)

egen byte desocupados_indice_woman = anycount(pobpcoac) if
e1==2, values(3 4 5)

egen byte desocupados_indice_woman_jefe = anycount(pobpcoac) if e1==2
& e3==1, values(3 4 5)

egen byte desocupados_indice_woman_no_jefe = anycount(pobpcoac) if
e1==2 & e3!=1, values(3 4 5)

egen desocupados = total(desocupados_indice)

egen desocupados_man = total(desocupados_indice_man)

egen desocupados_man_jefe = total(desocupados_indice_man_jefe)

egen desocupados_man_no_jefe = total(desocupados_indice_man_no_jefe)

egen desocupados_woman = total(desocupados_indice_woman)

egen desocupados_woman_jefe = total(desocupados_indice_woman_jefe)

egen desocupados_woman_no_jefe =
total(desocupados_indice_woman_no_jefe)

egen ocupados_indice = anycount (pobpcoac), values(2)

egen ocupados_indice_man = anycount(pobpcoac) if e1==1, values(2)

egen ocupados_indice_man_jefe = anycount(pobpcoac) if e1==1 & e3==1,
values(2)

egen ocupados_indice_man_no_jefe = anycount(pobpcoac) if e1==1 &
e3!=1, values(2)

egen ocupados_indice_woman = anycount(pobpcoac) if e1==2, values(2)

egen ocupados_indice_woman_jefe = anycount(pobpcoac) if e1==2
& e3==1, values(2)

egen ocupados_indice_woman_no_jefe = anycount(pobpcoac) if e1==2 &
e3!=1, values(2)

egen ocupados = total (ocupados_indice)

egen ocupados_man = total(ocupados_indice_man)

egen ocupados_man_jefe = total(ocupados_indice_man_jefe)

egen ocupados_man_no_jefe = total(ocupados_indice_man_no_jefe)

egen ocupados_woman = total(ocupados_indice_woman)

egen ocupados_woman_jefe = total(desocupados_indice_woman_jefe)

egen desocupados_woman_no_jefe =
total(desocupados_indice_woman_no_jefe)

generate pea=ocupados+desocupados

egen pei_indice = anycount (pobpcoac), values(6/11)

egen pei = total( pei_indice)

generate pet=pea+pei

egen pnet_indice = anycount (pobpcoac), values(1)

egen pnet = total( pnet_indice)

generate poblacion=pet+pnet

generate tasa_empleo=ocupados/pet

generate pet_ine=1620743

generate ocupados_expandidos=tasa_empleo*pet_ine
*
*   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/
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index