[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: RE: RE: best way to create iweight - code?
I have some code that I've used to do this and just updated it to v8.2.
It's short enough that I'm attaching it below, but you may find line
wrapping problems. The longest line is the one to label the new variable.
To apply this program to your problem you will need to append the datasets
together and have some identifier for the dataset that represents the
population you want to match to. For example:
keep age gender
gen byte pop=1
append using datasetB
replace pop=0 if pop==.
matchwt age gender , match(pop) gen(myweight)
drop if pop==1
This will create a new variable in datasetB called myweight that will
contain the weights that you want (I hope). Unlike the manual cross-tab
approach, there is no real technical limit to the number of variables you
can match on. You may want to first bin the age variable (e.g.,
0-5,6-10,etc) to lower the likelihood of no matches in the population,
unless you have a large datasetA
program define matchwt
*! M Blasnik Nov-03 v 2.0
syntax varlist [if] , match(str) gen(str)
tempvar binn pop binnP
marksample touse, strok
gen byte `pop'=cond(`match',1,0) if `touse'
tab `pop' if `touse', matcell(`counts')
bys `touse' `varlist' `pop': gen `binn'=_N if `touse'
by `touse' `varlist' (`pop'): gen `binnP'=`binn'[_N]*`pop'[_N]
label var `gen' "weights to match cases where `match' `if', based on
> De : email@example.com
<mailto:firstname.lastname@example.org%5DDe> la part de Lisa Jahns
> Envoyé : jeudi 13 novembre 2003 15:59
> À : email@example.com
> Objet : st: best way to create iweight?
> I have dataset "A" with some distribution of age (in years) and sex
> (0,1), and totally unrelated dataset "B" with some different
> distribution of age and sex. What is the most parsimonious way to
> create an iweight for individuals in dataset B that will give it the
> same age and sex distribution of dataset A?
> Thank you,
> Lisa Jahns
> University of North Carolina
* For searches and help try: