# Relationship between two randomly-generated variables

Using stata, I generate two random variables and regress them with each other.

clear
set obs 1000
gen rand1 = uniform()
gen rand2 = uniform()
reg rand1 rand2, nocons
reg rand2 rand1, nocons


And I found weird patterns.

1. How can both regressions have coefficient smaller than 1? Intuitively I can't get it.

2. Why are coefficients from both regressions always smaller than 1?

• See stats.stackexchange.com/questions/22718. Notice, too, that the formula for the slope estimate is a ratio of random variables. The expectation of the numerator is $1/4$ and that of the denominator is $1/3,$ implying that with large samples (and 1000 is sufficiently large) the expectation of the slope estimate will be close to $1/4/(1/3) = 3/4.$
– whuber
May 31, 2020 at 14:17
• Re (2): it's not always the case that both coefficient estimates are less than $1.$ This becomes clear when you use a smaller value of obs. Indeed, with obs set to 1, the expected value of either regression coefficient is infinite!
– whuber
Jun 1, 2020 at 14:38

Note that omitting the intercept the estimate for the coefficient $$\beta$$ is given by <source>

$$\hat{\beta} = \frac{\sum^n_{i=1} x_iy_i}{\sum^n_{i=1}x_i^2}$$

in other words dividing the sum of $$x$$ times $$y$$ by the sum of squares of $$x$$ $$-$$ can also take the mean. Due to the random ordering matching $$x$$ and $$y$$ values in the linear model you end up with a smaller numerator and as a result your coefficient will be smaller than 1.

I must admit that this is probably not an entirely satisfactory answer as it is based mainly on observed patterns; I don't know if there is a better mathematical explanation for it. You can check the former for yourself though. Just take the sum of $$xy$$ as they were generated and compare it with the sum when you order both variables (dividing them by the sum of squares of $$x$$).

• Hi: Note that the coefficient of the regression based on $y \sim x$ is not one over the coefficient of the regression based on $x \sim y$, if that's why you're puzzled by why they are both less than 1.0. May 30, 2020 at 22:23
• @mlofton I know that. But if the line emanating from (0,0) is lower than 45 degree line, I am wondering about the condition under which the opposite could be also lower than 45 degree line. May 31, 2020 at 0:20
• The mathematical explanation is cauchy schwarz inequality/chebyshev inequality
– Pig
May 31, 2020 at 17:13
• @user42459: Pig is probably correct but the easiest thing to do would be to just calculate $\hat{\beta}$ in both cases. You have the data and the formula. May 31, 2020 at 21:29
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 10, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://stats.stackexchange.com/questions/469482/relationship-between-two-randomly-generated-variables/469492", "fetch_time": 1701830767000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2023-50/segments/1700679100575.30/warc/CC-MAIN-20231206000253-20231206030253-00716.warc.gz", "warc_record_offset": 602557087, "warc_record_length": 42283, "token_count": 709, "char_count": 2651, "score": 3.84375, "int_score": 4, "crawl": "CC-MAIN-2023-50", "snapshot_type": "longest", "language": "en", "language_score": 0.9341009855270386, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00044-of-00064.parquet"}