Q:

Calculating sampling weights when I have sampled from a known population

I have a very large data (100+ million records)and I am estimating a complex random coefficients model and I can only comfortably use a million or so records. Iam interested in details in time and space so I have sampled on these attributes so that each  space-time cell has 10 records. Consequently some cells are overrepresented compared to the population and some are underrepresented. I also have several other variables -all of them categorical and because I can compare the obtained sample with the know frequencies in the population I can evaluate the under and over representation  of these types too.
I want to use sampling weights to rebalance the sample as in the population on a number of attributes simultaneously. Can I use a model whether the dependent variable is in sample or not and predictor variables based on type to derive these weights?
Any help much appreciated.

A:

I'll answer your question based on the information you've already provided. I don't see how these weights can be used in a random effects model, but that's not what you asked for.
1- Constructing sampling Weights
The cells in which you selected 10 observations each are known as   "sampling strata". You have 4 x 2 x 2 x 12 x 12 = 2,304 of them. Number  for convenience from $i = 1\ldots 2304$. You know $N_i$,
    the number of records in cell $i$.  Then the probability of
    selection for records  in cell $i$ is $f_i=\dfrac{10}{N_i}$, and the
    sampling weight is
$$
w_i = \frac{1}{f_i} =  \frac{N_i}{10}
$$
These are the "design" or "sampling" weights. 
2-  Balancing on other categorical variables  known for the entire population. 
The standard method for doing this is variously known as "raking", "ratio raking" or "sample balancing".  with the first common in the survey literature.  The technique is an application of interative proportional fitting (IPF). The commands take the design weights and alter them so them that the resulting weighted totals for categories match the known totals. 
References:
L Anderson and R Fricker "Raking: an important and often overlooked survey analysis tool"
http://faculty.nps.edu/rdfricke/docs/RakingArticleV2.2.pdf
Battaglia, Michael P, David Izrael, David C Hoaglin, and Martin R Frankel. 2004. Tips and tricks for raking survey data (aka sample balancing). Abt Associates 4740-4744.
http://www.amstat.org/sections/srms/Proceedings/y2004/files/Jsm2004-000074.pdf
Software:
SAS macros
http://abtassociates.com/Expertise/Surveys-and-Data-Collection/Raking-Survey-Data-%28a-k-a--Sample-Balancing%29.aspx
Stata:

ipfraking (Stas Kolenikov)   "findit ipfraking"
survgwt rake (Nicholas Winter) "ssc install survwgt"

R package survey (Tom Lumley) https://cran.r-project.org/web/packages/survey/index.html

